| Line Number |
../DebugInfoTest/example_mips_dbg.ll
|
Hit count |
Line Number |
../DebugInfoTest/example_mips.ll
|
Hit count |
| 1 |
//===- Attributor.h --- Module-wide attribute deduction ---------*- C++ -*-===// |
--- |
1 |
//===- Attributor.h --- Module-wide attribute deduction ---------*- C++ -*-===// |
--- |
| 2 |
// |
--- |
2 |
// |
--- |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
--- |
3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
--- |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
--- |
4 |
// See https://llvm.org/LICENSE.txt for license information. |
--- |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
--- |
5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
--- |
| 6 |
// |
--- |
6 |
// |
--- |
| 7 |
//===----------------------------------------------------------------------===// |
--- |
7 |
//===----------------------------------------------------------------------===// |
--- |
| 8 |
// |
--- |
8 |
// |
--- |
| 9 |
// Attributor: An inter procedural (abstract) "attribute" deduction framework. |
--- |
9 |
// Attributor: An inter procedural (abstract) "attribute" deduction framework. |
--- |
| 10 |
// |
--- |
10 |
// |
--- |
| 11 |
// The Attributor framework is an inter procedural abstract analysis (fixpoint |
--- |
11 |
// The Attributor framework is an inter procedural abstract analysis (fixpoint |
--- |
| 12 |
// iteration analysis). The goal is to allow easy deduction of new attributes as |
--- |
12 |
// iteration analysis). The goal is to allow easy deduction of new attributes as |
--- |
| 13 |
// well as information exchange between abstract attributes in-flight. |
--- |
13 |
// well as information exchange between abstract attributes in-flight. |
--- |
| 14 |
// |
--- |
14 |
// |
--- |
| 15 |
// The Attributor class is the driver and the link between the various abstract |
--- |
15 |
// The Attributor class is the driver and the link between the various abstract |
--- |
| 16 |
// attributes. The Attributor will iterate until a fixpoint state is reached by |
--- |
16 |
// attributes. The Attributor will iterate until a fixpoint state is reached by |
--- |
| 17 |
// all abstract attributes in-flight, or until it will enforce a pessimistic fix |
--- |
17 |
// all abstract attributes in-flight, or until it will enforce a pessimistic fix |
--- |
| 18 |
// point because an iteration limit is reached. |
--- |
18 |
// point because an iteration limit is reached. |
--- |
| 19 |
// |
--- |
19 |
// |
--- |
| 20 |
// Abstract attributes, derived from the AbstractAttribute class, actually |
--- |
20 |
// Abstract attributes, derived from the AbstractAttribute class, actually |
--- |
| 21 |
// describe properties of the code. They can correspond to actual LLVM-IR |
--- |
21 |
// describe properties of the code. They can correspond to actual LLVM-IR |
--- |
| 22 |
// attributes, or they can be more general, ultimately unrelated to LLVM-IR |
--- |
22 |
// attributes, or they can be more general, ultimately unrelated to LLVM-IR |
--- |
| 23 |
// attributes. The latter is useful when an abstract attributes provides |
--- |
23 |
// attributes. The latter is useful when an abstract attributes provides |
--- |
| 24 |
// information to other abstract attributes in-flight but we might not want to |
--- |
24 |
// information to other abstract attributes in-flight but we might not want to |
--- |
| 25 |
// manifest the information. The Attributor allows to query in-flight abstract |
--- |
25 |
// manifest the information. The Attributor allows to query in-flight abstract |
--- |
| 26 |
// attributes through the `Attributor::getAAFor` method (see the method |
--- |
26 |
// attributes through the `Attributor::getAAFor` method (see the method |
--- |
| 27 |
// description for an example). If the method is used by an abstract attribute |
--- |
27 |
// description for an example). If the method is used by an abstract attribute |
--- |
| 28 |
// P, and it results in an abstract attribute Q, the Attributor will |
--- |
28 |
// P, and it results in an abstract attribute Q, the Attributor will |
--- |
| 29 |
// automatically capture a potential dependence from Q to P. This dependence |
--- |
29 |
// automatically capture a potential dependence from Q to P. This dependence |
--- |
| 30 |
// will cause P to be reevaluated whenever Q changes in the future. |
--- |
30 |
// will cause P to be reevaluated whenever Q changes in the future. |
--- |
| 31 |
// |
--- |
31 |
// |
--- |
| 32 |
// The Attributor will only reevaluate abstract attributes that might have |
--- |
32 |
// The Attributor will only reevaluate abstract attributes that might have |
--- |
| 33 |
// changed since the last iteration. That means that the Attribute will not |
--- |
33 |
// changed since the last iteration. That means that the Attribute will not |
--- |
| 34 |
// revisit all instructions/blocks/functions in the module but only query |
--- |
34 |
// revisit all instructions/blocks/functions in the module but only query |
--- |
| 35 |
// an update from a subset of the abstract attributes. |
--- |
35 |
// an update from a subset of the abstract attributes. |
--- |
| 36 |
// |
--- |
36 |
// |
--- |
| 37 |
// The update method `AbstractAttribute::updateImpl` is implemented by the |
--- |
37 |
// The update method `AbstractAttribute::updateImpl` is implemented by the |
--- |
| 38 |
// specific "abstract attribute" subclasses. The method is invoked whenever the |
--- |
38 |
// specific "abstract attribute" subclasses. The method is invoked whenever the |
--- |
| 39 |
// currently assumed state (see the AbstractState class) might not be valid |
--- |
39 |
// currently assumed state (see the AbstractState class) might not be valid |
--- |
| 40 |
// anymore. This can, for example, happen if the state was dependent on another |
--- |
40 |
// anymore. This can, for example, happen if the state was dependent on another |
--- |
| 41 |
// abstract attribute that changed. In every invocation, the update method has |
--- |
41 |
// abstract attribute that changed. In every invocation, the update method has |
--- |
| 42 |
// to adjust the internal state of an abstract attribute to a point that is |
--- |
42 |
// to adjust the internal state of an abstract attribute to a point that is |
--- |
| 43 |
// justifiable by the underlying IR and the current state of abstract attributes |
--- |
43 |
// justifiable by the underlying IR and the current state of abstract attributes |
--- |
| 44 |
// in-flight. Since the IR is given and assumed to be valid, the information |
--- |
44 |
// in-flight. Since the IR is given and assumed to be valid, the information |
--- |
| 45 |
// derived from it can be assumed to hold. However, information derived from |
--- |
45 |
// derived from it can be assumed to hold. However, information derived from |
--- |
| 46 |
// other abstract attributes is conditional on various things. If the justifying |
--- |
46 |
// other abstract attributes is conditional on various things. If the justifying |
--- |
| 47 |
// state changed, the `updateImpl` has to revisit the situation and potentially |
--- |
47 |
// state changed, the `updateImpl` has to revisit the situation and potentially |
--- |
| 48 |
// find another justification or limit the optimistic assumes made. |
--- |
48 |
// find another justification or limit the optimistic assumes made. |
--- |
| 49 |
// |
--- |
49 |
// |
--- |
| 50 |
// Change is the key in this framework. Until a state of no-change, thus a |
--- |
50 |
// Change is the key in this framework. Until a state of no-change, thus a |
--- |
| 51 |
// fixpoint, is reached, the Attributor will query the abstract attributes |
--- |
51 |
// fixpoint, is reached, the Attributor will query the abstract attributes |
--- |
| 52 |
// in-flight to re-evaluate their state. If the (current) state is too |
--- |
52 |
// in-flight to re-evaluate their state. If the (current) state is too |
--- |
| 53 |
// optimistic, hence it cannot be justified anymore through other abstract |
--- |
53 |
// optimistic, hence it cannot be justified anymore through other abstract |
--- |
| 54 |
// attributes or the state of the IR, the state of the abstract attribute will |
--- |
54 |
// attributes or the state of the IR, the state of the abstract attribute will |
--- |
| 55 |
// have to change. Generally, we assume abstract attribute state to be a finite |
--- |
55 |
// have to change. Generally, we assume abstract attribute state to be a finite |
--- |
| 56 |
// height lattice and the update function to be monotone. However, these |
--- |
56 |
// height lattice and the update function to be monotone. However, these |
--- |
| 57 |
// conditions are not enforced because the iteration limit will guarantee |
--- |
57 |
// conditions are not enforced because the iteration limit will guarantee |
--- |
| 58 |
// termination. If an optimistic fixpoint is reached, or a pessimistic fix |
--- |
58 |
// termination. If an optimistic fixpoint is reached, or a pessimistic fix |
--- |
| 59 |
// point is enforced after a timeout, the abstract attributes are tasked to |
--- |
59 |
// point is enforced after a timeout, the abstract attributes are tasked to |
--- |
| 60 |
// manifest their result in the IR for passes to come. |
--- |
60 |
// manifest their result in the IR for passes to come. |
--- |
| 61 |
// |
--- |
61 |
// |
--- |
| 62 |
// Attribute manifestation is not mandatory. If desired, there is support to |
--- |
62 |
// Attribute manifestation is not mandatory. If desired, there is support to |
--- |
| 63 |
// generate a single or multiple LLVM-IR attributes already in the helper struct |
--- |
63 |
// generate a single or multiple LLVM-IR attributes already in the helper struct |
--- |
| 64 |
// IRAttribute. In the simplest case, a subclass inherits from IRAttribute with |
--- |
64 |
// IRAttribute. In the simplest case, a subclass inherits from IRAttribute with |
--- |
| 65 |
// a proper Attribute::AttrKind as template parameter. The Attributor |
--- |
65 |
// a proper Attribute::AttrKind as template parameter. The Attributor |
--- |
| 66 |
// manifestation framework will then create and place a new attribute if it is |
--- |
66 |
// manifestation framework will then create and place a new attribute if it is |
--- |
| 67 |
// allowed to do so (based on the abstract state). Other use cases can be |
--- |
67 |
// allowed to do so (based on the abstract state). Other use cases can be |
--- |
| 68 |
// achieved by overloading AbstractAttribute or IRAttribute methods. |
--- |
68 |
// achieved by overloading AbstractAttribute or IRAttribute methods. |
--- |
| 69 |
// |
--- |
69 |
// |
--- |
| 70 |
// |
--- |
70 |
// |
--- |
| 71 |
// The "mechanics" of adding a new "abstract attribute": |
--- |
71 |
// The "mechanics" of adding a new "abstract attribute": |
--- |
| 72 |
// - Define a class (transitively) inheriting from AbstractAttribute and one |
--- |
72 |
// - Define a class (transitively) inheriting from AbstractAttribute and one |
--- |
| 73 |
// (which could be the same) that (transitively) inherits from AbstractState. |
--- |
73 |
// (which could be the same) that (transitively) inherits from AbstractState. |
--- |
| 74 |
// For the latter, consider the already available BooleanState and |
--- |
74 |
// For the latter, consider the already available BooleanState and |
--- |
| 75 |
// {Inc,Dec,Bit}IntegerState if they fit your needs, e.g., you require only a |
--- |
75 |
// {Inc,Dec,Bit}IntegerState if they fit your needs, e.g., you require only a |
--- |
| 76 |
// number tracking or bit-encoding. |
--- |
76 |
// number tracking or bit-encoding. |
--- |
| 77 |
// - Implement all pure methods. Also use overloading if the attribute is not |
--- |
77 |
// - Implement all pure methods. Also use overloading if the attribute is not |
--- |
| 78 |
// conforming with the "default" behavior: A (set of) LLVM-IR attribute(s) for |
--- |
78 |
// conforming with the "default" behavior: A (set of) LLVM-IR attribute(s) for |
--- |
| 79 |
// an argument, call site argument, function return value, or function. See |
--- |
79 |
// an argument, call site argument, function return value, or function. See |
--- |
| 80 |
// the class and method descriptions for more information on the two |
--- |
80 |
// the class and method descriptions for more information on the two |
--- |
| 81 |
// "Abstract" classes and their respective methods. |
--- |
81 |
// "Abstract" classes and their respective methods. |
--- |
| 82 |
// - Register opportunities for the new abstract attribute in the |
--- |
82 |
// - Register opportunities for the new abstract attribute in the |
--- |
| 83 |
// `Attributor::identifyDefaultAbstractAttributes` method if it should be |
--- |
83 |
// `Attributor::identifyDefaultAbstractAttributes` method if it should be |
--- |
| 84 |
// counted as a 'default' attribute. |
--- |
84 |
// counted as a 'default' attribute. |
--- |
| 85 |
// - Add sufficient tests. |
--- |
85 |
// - Add sufficient tests. |
--- |
| 86 |
// - Add a Statistics object for bookkeeping. If it is a simple (set of) |
--- |
86 |
// - Add a Statistics object for bookkeeping. If it is a simple (set of) |
--- |
| 87 |
// attribute(s) manifested through the Attributor manifestation framework, see |
--- |
87 |
// attribute(s) manifested through the Attributor manifestation framework, see |
--- |
| 88 |
// the bookkeeping function in Attributor.cpp. |
--- |
88 |
// the bookkeeping function in Attributor.cpp. |
--- |
| 89 |
// - If instructions with a certain opcode are interesting to the attribute, add |
--- |
89 |
// - If instructions with a certain opcode are interesting to the attribute, add |
--- |
| 90 |
// that opcode to the switch in `Attributor::identifyAbstractAttributes`. This |
--- |
90 |
// that opcode to the switch in `Attributor::identifyAbstractAttributes`. This |
--- |
| 91 |
// will make it possible to query all those instructions through the |
--- |
91 |
// will make it possible to query all those instructions through the |
--- |
| 92 |
// `InformationCache::getOpcodeInstMapForFunction` interface and eliminate the |
--- |
92 |
// `InformationCache::getOpcodeInstMapForFunction` interface and eliminate the |
--- |
| 93 |
// need to traverse the IR repeatedly. |
--- |
93 |
// need to traverse the IR repeatedly. |
--- |
| 94 |
// |
--- |
94 |
// |
--- |
| 95 |
//===----------------------------------------------------------------------===// |
--- |
95 |
//===----------------------------------------------------------------------===// |
--- |
| 96 |
|
--- |
96 |
|
--- |
| 97 |
#ifndef LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H |
--- |
97 |
#ifndef LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H |
--- |
| 98 |
#define LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H |
--- |
98 |
#define LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H |
--- |
| 99 |
|
--- |
99 |
|
--- |
| 100 |
#include "llvm/ADT/DenseSet.h" |
--- |
100 |
#include "llvm/ADT/DenseSet.h" |
--- |
| 101 |
#include "llvm/ADT/GraphTraits.h" |
--- |
101 |
#include "llvm/ADT/GraphTraits.h" |
--- |
| 102 |
#include "llvm/ADT/MapVector.h" |
--- |
102 |
#include "llvm/ADT/MapVector.h" |
--- |
| 103 |
#include "llvm/ADT/STLExtras.h" |
--- |
103 |
#include "llvm/ADT/STLExtras.h" |
--- |
| 104 |
#include "llvm/ADT/SetOperations.h" |
--- |
104 |
#include "llvm/ADT/SetOperations.h" |
--- |
| 105 |
#include "llvm/ADT/SetVector.h" |
--- |
105 |
#include "llvm/ADT/SetVector.h" |
--- |
| 106 |
#include "llvm/ADT/iterator.h" |
--- |
106 |
#include "llvm/ADT/iterator.h" |
--- |
| 107 |
#include "llvm/Analysis/AssumeBundleQueries.h" |
--- |
107 |
#include "llvm/Analysis/AssumeBundleQueries.h" |
--- |
| 108 |
#include "llvm/Analysis/CFG.h" |
--- |
108 |
#include "llvm/Analysis/CFG.h" |
--- |
| 109 |
#include "llvm/Analysis/CGSCCPassManager.h" |
--- |
109 |
#include "llvm/Analysis/CGSCCPassManager.h" |
--- |
| 110 |
#include "llvm/Analysis/LazyCallGraph.h" |
--- |
110 |
#include "llvm/Analysis/LazyCallGraph.h" |
--- |
| 111 |
#include "llvm/Analysis/LoopInfo.h" |
--- |
111 |
#include "llvm/Analysis/LoopInfo.h" |
--- |
| 112 |
#include "llvm/Analysis/MemoryLocation.h" |
--- |
112 |
#include "llvm/Analysis/MemoryLocation.h" |
--- |
| 113 |
#include "llvm/Analysis/MustExecute.h" |
--- |
113 |
#include "llvm/Analysis/MustExecute.h" |
--- |
| 114 |
#include "llvm/Analysis/OptimizationRemarkEmitter.h" |
--- |
114 |
#include "llvm/Analysis/OptimizationRemarkEmitter.h" |
--- |
| 115 |
#include "llvm/Analysis/PostDominators.h" |
--- |
115 |
#include "llvm/Analysis/PostDominators.h" |
--- |
| 116 |
#include "llvm/Analysis/TargetLibraryInfo.h" |
--- |
116 |
#include "llvm/Analysis/TargetLibraryInfo.h" |
--- |
| 117 |
#include "llvm/IR/AbstractCallSite.h" |
--- |
117 |
#include "llvm/IR/AbstractCallSite.h" |
--- |
| 118 |
#include "llvm/IR/Attributes.h" |
--- |
118 |
#include "llvm/IR/Attributes.h" |
--- |
| 119 |
#include "llvm/IR/ConstantRange.h" |
--- |
119 |
#include "llvm/IR/ConstantRange.h" |
--- |
| 120 |
#include "llvm/IR/Constants.h" |
--- |
120 |
#include "llvm/IR/Constants.h" |
--- |
| 121 |
#include "llvm/IR/InstIterator.h" |
--- |
121 |
#include "llvm/IR/InstIterator.h" |
--- |
| 122 |
#include "llvm/IR/Instruction.h" |
--- |
122 |
#include "llvm/IR/Instruction.h" |
--- |
| 123 |
#include "llvm/IR/Instructions.h" |
--- |
123 |
#include "llvm/IR/Instructions.h" |
--- |
| 124 |
#include "llvm/IR/PassManager.h" |
--- |
124 |
#include "llvm/IR/PassManager.h" |
--- |
| 125 |
#include "llvm/IR/Value.h" |
--- |
125 |
#include "llvm/IR/Value.h" |
--- |
| 126 |
#include "llvm/Support/Alignment.h" |
--- |
126 |
#include "llvm/Support/Alignment.h" |
--- |
| 127 |
#include "llvm/Support/Allocator.h" |
--- |
127 |
#include "llvm/Support/Allocator.h" |
--- |
| 128 |
#include "llvm/Support/Casting.h" |
--- |
128 |
#include "llvm/Support/Casting.h" |
--- |
| 129 |
#include "llvm/Support/DOTGraphTraits.h" |
--- |
129 |
#include "llvm/Support/DOTGraphTraits.h" |
--- |
| 130 |
#include "llvm/Support/ErrorHandling.h" |
--- |
130 |
#include "llvm/Support/ErrorHandling.h" |
--- |
| 131 |
#include "llvm/Support/ModRef.h" |
--- |
131 |
#include "llvm/Support/ModRef.h" |
--- |
| 132 |
#include "llvm/Support/TimeProfiler.h" |
--- |
132 |
#include "llvm/Support/TimeProfiler.h" |
--- |
| 133 |
#include "llvm/TargetParser/Triple.h" |
--- |
133 |
#include "llvm/TargetParser/Triple.h" |
--- |
| 134 |
#include "llvm/Transforms/Utils/CallGraphUpdater.h" |
--- |
134 |
#include "llvm/Transforms/Utils/CallGraphUpdater.h" |
--- |
| 135 |
|
--- |
135 |
|
--- |
| 136 |
#include |
--- |
136 |
#include |
--- |
| 137 |
#include |
--- |
137 |
#include |
--- |
| 138 |
#include |
--- |
138 |
#include |
--- |
| 139 |
|
--- |
139 |
|
--- |
| 140 |
namespace llvm { |
--- |
140 |
namespace llvm { |
--- |
| 141 |
|
--- |
141 |
|
--- |
| 142 |
class DataLayout; |
--- |
142 |
class DataLayout; |
--- |
| 143 |
class LLVMContext; |
--- |
143 |
class LLVMContext; |
--- |
| 144 |
class Pass; |
--- |
144 |
class Pass; |
--- |
| 145 |
template class function_ref; |
--- |
145 |
template class function_ref; |
--- |
| 146 |
struct AADepGraphNode; |
--- |
146 |
struct AADepGraphNode; |
--- |
| 147 |
struct AADepGraph; |
--- |
147 |
struct AADepGraph; |
--- |
| 148 |
struct Attributor; |
--- |
148 |
struct Attributor; |
--- |
| 149 |
struct AbstractAttribute; |
--- |
149 |
struct AbstractAttribute; |
--- |
| 150 |
struct InformationCache; |
--- |
150 |
struct InformationCache; |
--- |
| 151 |
struct AAIsDead; |
--- |
151 |
struct AAIsDead; |
--- |
| 152 |
struct AttributorCallGraph; |
--- |
152 |
struct AttributorCallGraph; |
--- |
| 153 |
struct IRPosition; |
--- |
153 |
struct IRPosition; |
--- |
| 154 |
|
--- |
154 |
|
--- |
| 155 |
class Function; |
--- |
155 |
class Function; |
--- |
| 156 |
|
--- |
156 |
|
--- |
| 157 |
/// Abstract Attribute helper functions. |
--- |
157 |
/// Abstract Attribute helper functions. |
--- |
| 158 |
namespace AA { |
--- |
158 |
namespace AA { |
--- |
| 159 |
using InstExclusionSetTy = SmallPtrSet; |
--- |
159 |
using InstExclusionSetTy = SmallPtrSet; |
--- |
| 160 |
|
--- |
160 |
|
--- |
| 161 |
enum class GPUAddressSpace : unsigned { |
--- |
161 |
enum class GPUAddressSpace : unsigned { |
--- |
| 162 |
Generic = 0, |
--- |
162 |
Generic = 0, |
--- |
| 163 |
Global = 1, |
--- |
163 |
Global = 1, |
--- |
| 164 |
Shared = 3, |
--- |
164 |
Shared = 3, |
--- |
| 165 |
Constant = 4, |
--- |
165 |
Constant = 4, |
--- |
| 166 |
Local = 5, |
--- |
166 |
Local = 5, |
--- |
| 167 |
}; |
--- |
167 |
}; |
--- |
| 168 |
|
--- |
168 |
|
--- |
| 169 |
/// Return true iff \p M target a GPU (and we can use GPU AS reasoning). |
--- |
169 |
/// Return true iff \p M target a GPU (and we can use GPU AS reasoning). |
--- |
| 170 |
bool isGPU(const Module &M); |
--- |
170 |
bool isGPU(const Module &M); |
--- |
| 171 |
|
--- |
171 |
|
--- |
| 172 |
/// Flags to distinguish intra-procedural queries from *potentially* |
--- |
172 |
/// Flags to distinguish intra-procedural queries from *potentially* |
--- |
| 173 |
/// inter-procedural queries. Not that information can be valid for both and |
--- |
173 |
/// inter-procedural queries. Not that information can be valid for both and |
--- |
| 174 |
/// therefore both bits might be set. |
--- |
174 |
/// therefore both bits might be set. |
--- |
| 175 |
enum ValueScope : uint8_t { |
--- |
175 |
enum ValueScope : uint8_t { |
--- |
| 176 |
Intraprocedural = 1, |
--- |
176 |
Intraprocedural = 1, |
--- |
| 177 |
Interprocedural = 2, |
--- |
177 |
Interprocedural = 2, |
--- |
| 178 |
AnyScope = Intraprocedural | Interprocedural, |
--- |
178 |
AnyScope = Intraprocedural | Interprocedural, |
--- |
| 179 |
}; |
--- |
179 |
}; |
--- |
| 180 |
|
--- |
180 |
|
--- |
| 181 |
struct ValueAndContext : public std::pair { |
--- |
181 |
struct ValueAndContext : public std::pair { |
--- |
| 182 |
using Base = std::pair; |
--- |
182 |
using Base = std::pair; |
--- |
| 183 |
ValueAndContext(const Base &B) : Base(B) {} |
--- |
183 |
ValueAndContext(const Base &B) : Base(B) {} |
--- |
| 184 |
ValueAndContext(Value &V, const Instruction *CtxI) : Base(&V, CtxI) {} |
0 |
184 |
ValueAndContext(Value &V, const Instruction *CtxI) : Base(&V, CtxI) {} |
0 |
| 185 |
ValueAndContext(Value &V, const Instruction &CtxI) : Base(&V, &CtxI) {} |
--- |
185 |
ValueAndContext(Value &V, const Instruction &CtxI) : Base(&V, &CtxI) {} |
--- |
| 186 |
|
--- |
186 |
|
--- |
| 187 |
Value *getValue() const { return this->first; } |
0 |
187 |
Value *getValue() const { return this->first; } |
0 |
| 188 |
const Instruction *getCtxI() const { return this->second; } |
0 |
188 |
const Instruction *getCtxI() const { return this->second; } |
0 |
| 189 |
}; |
--- |
189 |
}; |
--- |
| 190 |
|
--- |
190 |
|
--- |
| 191 |
/// Return true if \p I is a `nosync` instruction. Use generic reasoning and |
--- |
191 |
/// Return true if \p I is a `nosync` instruction. Use generic reasoning and |
--- |
| 192 |
/// potentially the corresponding AANoSync. |
--- |
192 |
/// potentially the corresponding AANoSync. |
--- |
| 193 |
bool isNoSyncInst(Attributor &A, const Instruction &I, |
--- |
193 |
bool isNoSyncInst(Attributor &A, const Instruction &I, |
--- |
| 194 |
const AbstractAttribute &QueryingAA); |
--- |
194 |
const AbstractAttribute &QueryingAA); |
--- |
| 195 |
|
--- |
195 |
|
--- |
| 196 |
/// Return true if \p V is dynamically unique, that is, there are no two |
--- |
196 |
/// Return true if \p V is dynamically unique, that is, there are no two |
--- |
| 197 |
/// "instances" of \p V at runtime with different values. |
--- |
197 |
/// "instances" of \p V at runtime with different values. |
--- |
| 198 |
/// Note: If \p ForAnalysisOnly is set we only check that the Attributor will |
--- |
198 |
/// Note: If \p ForAnalysisOnly is set we only check that the Attributor will |
--- |
| 199 |
/// never use \p V to represent two "instances" not that \p V could not |
--- |
199 |
/// never use \p V to represent two "instances" not that \p V could not |
--- |
| 200 |
/// technically represent them. |
--- |
200 |
/// technically represent them. |
--- |
| 201 |
bool isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA, |
--- |
201 |
bool isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA, |
--- |
| 202 |
const Value &V, bool ForAnalysisOnly = true); |
--- |
202 |
const Value &V, bool ForAnalysisOnly = true); |
--- |
| 203 |
|
--- |
203 |
|
--- |
| 204 |
/// Return true if \p V is a valid value in \p Scope, that is a constant or an |
--- |
204 |
/// Return true if \p V is a valid value in \p Scope, that is a constant or an |
--- |
| 205 |
/// instruction/argument of \p Scope. |
--- |
205 |
/// instruction/argument of \p Scope. |
--- |
| 206 |
bool isValidInScope(const Value &V, const Function *Scope); |
--- |
206 |
bool isValidInScope(const Value &V, const Function *Scope); |
--- |
| 207 |
|
--- |
207 |
|
--- |
| 208 |
/// Return true if the value of \p VAC is a valid at the position of \p VAC, |
--- |
208 |
/// Return true if the value of \p VAC is a valid at the position of \p VAC, |
--- |
| 209 |
/// that is a constant, an argument of the same function, or an instruction in |
--- |
209 |
/// that is a constant, an argument of the same function, or an instruction in |
--- |
| 210 |
/// that function that dominates the position. |
--- |
210 |
/// that function that dominates the position. |
--- |
| 211 |
bool isValidAtPosition(const ValueAndContext &VAC, InformationCache &InfoCache); |
--- |
211 |
bool isValidAtPosition(const ValueAndContext &VAC, InformationCache &InfoCache); |
--- |
| 212 |
|
--- |
212 |
|
--- |
| 213 |
/// Try to convert \p V to type \p Ty without introducing new instructions. If |
--- |
213 |
/// Try to convert \p V to type \p Ty without introducing new instructions. If |
--- |
| 214 |
/// this is not possible return `nullptr`. Note: this function basically knows |
--- |
214 |
/// this is not possible return `nullptr`. Note: this function basically knows |
--- |
| 215 |
/// how to cast various constants. |
--- |
215 |
/// how to cast various constants. |
--- |
| 216 |
Value *getWithType(Value &V, Type &Ty); |
--- |
216 |
Value *getWithType(Value &V, Type &Ty); |
--- |
| 217 |
|
--- |
217 |
|
--- |
| 218 |
/// Return the combination of \p A and \p B such that the result is a possible |
--- |
218 |
/// Return the combination of \p A and \p B such that the result is a possible |
--- |
| 219 |
/// value of both. \p B is potentially casted to match the type \p Ty or the |
--- |
219 |
/// value of both. \p B is potentially casted to match the type \p Ty or the |
--- |
| 220 |
/// type of \p A if \p Ty is null. |
--- |
220 |
/// type of \p A if \p Ty is null. |
--- |
| 221 |
/// |
--- |
221 |
/// |
--- |
| 222 |
/// Examples: |
--- |
222 |
/// Examples: |
--- |
| 223 |
/// X + none => X |
--- |
223 |
/// X + none => X |
--- |
| 224 |
/// not_none + undef => not_none |
--- |
224 |
/// not_none + undef => not_none |
--- |
| 225 |
/// V1 + V2 => nullptr |
--- |
225 |
/// V1 + V2 => nullptr |
--- |
| 226 |
std::optional |
--- |
226 |
std::optional |
--- |
| 227 |
combineOptionalValuesInAAValueLatice(const std::optional &A, |
--- |
227 |
combineOptionalValuesInAAValueLatice(const std::optional &A, |
--- |
| 228 |
const std::optional &B, Type *Ty); |
--- |
228 |
const std::optional &B, Type *Ty); |
--- |
| 229 |
|
--- |
229 |
|
--- |
| 230 |
/// Helper to represent an access offset and size, with logic to deal with |
--- |
230 |
/// Helper to represent an access offset and size, with logic to deal with |
--- |
| 231 |
/// uncertainty and check for overlapping accesses. |
--- |
231 |
/// uncertainty and check for overlapping accesses. |
--- |
| 232 |
struct RangeTy { |
--- |
232 |
struct RangeTy { |
--- |
| 233 |
int64_t Offset = Unassigned; |
--- |
233 |
int64_t Offset = Unassigned; |
--- |
| 234 |
int64_t Size = Unassigned; |
--- |
234 |
int64_t Size = Unassigned; |
--- |
| 235 |
|
--- |
235 |
|
--- |
| 236 |
RangeTy(int64_t Offset, int64_t Size) : Offset(Offset), Size(Size) {} |
--- |
236 |
RangeTy(int64_t Offset, int64_t Size) : Offset(Offset), Size(Size) {} |
--- |
| 237 |
RangeTy() = default; |
--- |
237 |
RangeTy() = default; |
--- |
| 238 |
static RangeTy getUnknown() { return RangeTy{Unknown, Unknown}; } |
--- |
238 |
static RangeTy getUnknown() { return RangeTy{Unknown, Unknown}; } |
--- |
| 239 |
|
--- |
239 |
|
--- |
| 240 |
/// Return true if offset or size are unknown. |
--- |
240 |
/// Return true if offset or size are unknown. |
--- |
| 241 |
bool offsetOrSizeAreUnknown() const { |
0 |
241 |
bool offsetOrSizeAreUnknown() const { |
0 |
| 242 |
return Offset == RangeTy::Unknown || Size == RangeTy::Unknown; |
0 |
242 |
return Offset == RangeTy::Unknown || Size == RangeTy::Unknown; |
0 |
| 243 |
} |
--- |
243 |
} |
--- |
| 244 |
|
--- |
244 |
|
--- |
| 245 |
/// Return true if offset and size are unknown, thus this is the default |
--- |
245 |
/// Return true if offset and size are unknown, thus this is the default |
--- |
| 246 |
/// unknown object. |
--- |
246 |
/// unknown object. |
--- |
| 247 |
bool offsetAndSizeAreUnknown() const { |
--- |
247 |
bool offsetAndSizeAreUnknown() const { |
--- |
| 248 |
return Offset == RangeTy::Unknown && Size == RangeTy::Unknown; |
--- |
248 |
return Offset == RangeTy::Unknown && Size == RangeTy::Unknown; |
--- |
| 249 |
} |
--- |
249 |
} |
--- |
| 250 |
|
--- |
250 |
|
--- |
| 251 |
/// Return true if the offset and size are unassigned. |
--- |
251 |
/// Return true if the offset and size are unassigned. |
--- |
| 252 |
bool isUnassigned() const { |
0 |
252 |
bool isUnassigned() const { |
0 |
| 253 |
assert((Offset == RangeTy::Unassigned) == (Size == RangeTy::Unassigned) && |
0 |
253 |
assert((Offset == RangeTy::Unassigned) == (Size == RangeTy::Unassigned) && |
0 |
| 254 |
"Inconsistent state!"); |
--- |
254 |
"Inconsistent state!"); |
--- |
| 255 |
return Offset == RangeTy::Unassigned; |
0 |
255 |
return Offset == RangeTy::Unassigned; |
0 |
| 256 |
} |
--- |
256 |
} |
--- |
| 257 |
|
--- |
257 |
|
--- |
| 258 |
/// Return true if this offset and size pair might describe an address that |
--- |
258 |
/// Return true if this offset and size pair might describe an address that |
--- |
| 259 |
/// overlaps with \p Range. |
--- |
259 |
/// overlaps with \p Range. |
--- |
| 260 |
bool mayOverlap(const RangeTy &Range) const { |
--- |
260 |
bool mayOverlap(const RangeTy &Range) const { |
--- |
| 261 |
// Any unknown value and we are giving up -> overlap. |
--- |
261 |
// Any unknown value and we are giving up -> overlap. |
--- |
| 262 |
if (offsetOrSizeAreUnknown() || Range.offsetOrSizeAreUnknown()) |
--- |
262 |
if (offsetOrSizeAreUnknown() || Range.offsetOrSizeAreUnknown()) |
--- |
| 263 |
return true; |
--- |
263 |
return true; |
--- |
| 264 |
|
--- |
264 |
|
--- |
| 265 |
// Check if one offset point is in the other interval [offset, |
--- |
265 |
// Check if one offset point is in the other interval [offset, |
--- |
| 266 |
// offset+size]. |
--- |
266 |
// offset+size]. |
--- |
| 267 |
return Range.Offset + Range.Size > Offset && Range.Offset < Offset + Size; |
--- |
267 |
return Range.Offset + Range.Size > Offset && Range.Offset < Offset + Size; |
--- |
| 268 |
} |
--- |
268 |
} |
--- |
| 269 |
|
--- |
269 |
|
--- |
| 270 |
RangeTy &operator&=(const RangeTy &R) { |
--- |
270 |
RangeTy &operator&=(const RangeTy &R) { |
--- |
| 271 |
if (R.isUnassigned()) |
--- |
271 |
if (R.isUnassigned()) |
--- |
| 272 |
return *this; |
--- |
272 |
return *this; |
--- |
| 273 |
if (isUnassigned()) |
--- |
273 |
if (isUnassigned()) |
--- |
| 274 |
return *this = R; |
--- |
274 |
return *this = R; |
--- |
| 275 |
if (Offset == Unknown || R.Offset == Unknown) |
--- |
275 |
if (Offset == Unknown || R.Offset == Unknown) |
--- |
| 276 |
Offset = Unknown; |
--- |
276 |
Offset = Unknown; |
--- |
| 277 |
if (Size == Unknown || R.Size == Unknown) |
--- |
277 |
if (Size == Unknown || R.Size == Unknown) |
--- |
| 278 |
Size = Unknown; |
--- |
278 |
Size = Unknown; |
--- |
| 279 |
if (offsetAndSizeAreUnknown()) |
--- |
279 |
if (offsetAndSizeAreUnknown()) |
--- |
| 280 |
return *this; |
--- |
280 |
return *this; |
--- |
| 281 |
if (Offset == Unknown) { |
--- |
281 |
if (Offset == Unknown) { |
--- |
| 282 |
Size = std::max(Size, R.Size); |
--- |
282 |
Size = std::max(Size, R.Size); |
--- |
| 283 |
} else if (Size == Unknown) { |
--- |
283 |
} else if (Size == Unknown) { |
--- |
| 284 |
Offset = std::min(Offset, R.Offset); |
--- |
284 |
Offset = std::min(Offset, R.Offset); |
--- |
| 285 |
} else { |
--- |
285 |
} else { |
--- |
| 286 |
Offset = std::min(Offset, R.Offset); |
--- |
286 |
Offset = std::min(Offset, R.Offset); |
--- |
| 287 |
Size = std::max(Offset + Size, R.Offset + R.Size) - Offset; |
--- |
287 |
Size = std::max(Offset + Size, R.Offset + R.Size) - Offset; |
--- |
| 288 |
} |
--- |
288 |
} |
--- |
| 289 |
return *this; |
--- |
289 |
return *this; |
--- |
| 290 |
} |
--- |
290 |
} |
--- |
| 291 |
|
--- |
291 |
|
--- |
| 292 |
/// Comparison for sorting ranges by offset. |
--- |
292 |
/// Comparison for sorting ranges by offset. |
--- |
| 293 |
/// |
--- |
293 |
/// |
--- |
| 294 |
/// Returns true if the offset \p L is less than that of \p R. |
--- |
294 |
/// Returns true if the offset \p L is less than that of \p R. |
--- |
| 295 |
inline static bool OffsetLessThan(const RangeTy &L, const RangeTy &R) { |
--- |
295 |
inline static bool OffsetLessThan(const RangeTy &L, const RangeTy &R) { |
--- |
| 296 |
return L.Offset < R.Offset; |
--- |
296 |
return L.Offset < R.Offset; |
--- |
| 297 |
} |
--- |
297 |
} |
--- |
| 298 |
|
--- |
298 |
|
--- |
| 299 |
/// Constants used to represent special offsets or sizes. |
--- |
299 |
/// Constants used to represent special offsets or sizes. |
--- |
| 300 |
/// - We cannot assume that Offsets and Size are non-negative. |
--- |
300 |
/// - We cannot assume that Offsets and Size are non-negative. |
--- |
| 301 |
/// - The constants should not clash with DenseMapInfo, such as EmptyKey |
--- |
301 |
/// - The constants should not clash with DenseMapInfo, such as EmptyKey |
--- |
| 302 |
/// (INT64_MAX) and TombstoneKey (INT64_MIN). |
--- |
302 |
/// (INT64_MAX) and TombstoneKey (INT64_MIN). |
--- |
| 303 |
/// We use values "in the middle" of the 64 bit range to represent these |
--- |
303 |
/// We use values "in the middle" of the 64 bit range to represent these |
--- |
| 304 |
/// special cases. |
--- |
304 |
/// special cases. |
--- |
| 305 |
static constexpr int64_t Unassigned = std::numeric_limits::min(); |
--- |
305 |
static constexpr int64_t Unassigned = std::numeric_limits::min(); |
--- |
| 306 |
static constexpr int64_t Unknown = std::numeric_limits::max(); |
--- |
306 |
static constexpr int64_t Unknown = std::numeric_limits::max(); |
--- |
| 307 |
}; |
--- |
307 |
}; |
--- |
| 308 |
|
--- |
308 |
|
--- |
| 309 |
inline raw_ostream &operator<<(raw_ostream &OS, const RangeTy &R) { |
--- |
309 |
inline raw_ostream &operator<<(raw_ostream &OS, const RangeTy &R) { |
--- |
| 310 |
OS << "[" << R.Offset << ", " << R.Size << "]"; |
--- |
310 |
OS << "[" << R.Offset << ", " << R.Size << "]"; |
--- |
| 311 |
return OS; |
--- |
311 |
return OS; |
--- |
| 312 |
} |
--- |
312 |
} |
--- |
| 313 |
|
--- |
313 |
|
--- |
| 314 |
inline bool operator==(const RangeTy &A, const RangeTy &B) { |
--- |
314 |
inline bool operator==(const RangeTy &A, const RangeTy &B) { |
--- |
| 315 |
return A.Offset == B.Offset && A.Size == B.Size; |
--- |
315 |
return A.Offset == B.Offset && A.Size == B.Size; |
--- |
| 316 |
} |
--- |
316 |
} |
--- |
| 317 |
|
--- |
317 |
|
--- |
| 318 |
inline bool operator!=(const RangeTy &A, const RangeTy &B) { return !(A == B); } |
--- |
318 |
inline bool operator!=(const RangeTy &A, const RangeTy &B) { return !(A == B); } |
--- |
| 319 |
|
--- |
319 |
|
--- |
| 320 |
/// Return the initial value of \p Obj with type \p Ty if that is a constant. |
--- |
320 |
/// Return the initial value of \p Obj with type \p Ty if that is a constant. |
--- |
| 321 |
Constant *getInitialValueForObj(Attributor &A, Value &Obj, Type &Ty, |
--- |
321 |
Constant *getInitialValueForObj(Attributor &A, Value &Obj, Type &Ty, |
--- |
| 322 |
const TargetLibraryInfo *TLI, |
--- |
322 |
const TargetLibraryInfo *TLI, |
--- |
| 323 |
const DataLayout &DL, |
--- |
323 |
const DataLayout &DL, |
--- |
| 324 |
RangeTy *RangePtr = nullptr); |
--- |
324 |
RangeTy *RangePtr = nullptr); |
--- |
| 325 |
|
--- |
325 |
|
--- |
| 326 |
/// Collect all potential values \p LI could read into \p PotentialValues. That |
--- |
326 |
/// Collect all potential values \p LI could read into \p PotentialValues. That |
--- |
| 327 |
/// is, the only values read by \p LI are assumed to be known and all are in |
--- |
327 |
/// is, the only values read by \p LI are assumed to be known and all are in |
--- |
| 328 |
/// \p PotentialValues. \p PotentialValueOrigins will contain all the |
--- |
328 |
/// \p PotentialValues. \p PotentialValueOrigins will contain all the |
--- |
| 329 |
/// instructions that might have put a potential value into \p PotentialValues. |
--- |
329 |
/// instructions that might have put a potential value into \p PotentialValues. |
--- |
| 330 |
/// Dependences onto \p QueryingAA are properly tracked, \p |
--- |
330 |
/// Dependences onto \p QueryingAA are properly tracked, \p |
--- |
| 331 |
/// UsedAssumedInformation will inform the caller if assumed information was |
--- |
331 |
/// UsedAssumedInformation will inform the caller if assumed information was |
--- |
| 332 |
/// used. |
--- |
332 |
/// used. |
--- |
| 333 |
/// |
--- |
333 |
/// |
--- |
| 334 |
/// \returns True if the assumed potential copies are all in \p PotentialValues, |
--- |
334 |
/// \returns True if the assumed potential copies are all in \p PotentialValues, |
--- |
| 335 |
/// false if something went wrong and the copies could not be |
--- |
335 |
/// false if something went wrong and the copies could not be |
--- |
| 336 |
/// determined. |
--- |
336 |
/// determined. |
--- |
| 337 |
bool getPotentiallyLoadedValues( |
--- |
337 |
bool getPotentiallyLoadedValues( |
--- |
| 338 |
Attributor &A, LoadInst &LI, SmallSetVector &PotentialValues, |
--- |
338 |
Attributor &A, LoadInst &LI, SmallSetVector &PotentialValues, |
--- |
| 339 |
SmallSetVector &PotentialValueOrigins, |
--- |
339 |
SmallSetVector &PotentialValueOrigins, |
--- |
| 340 |
const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, |
--- |
340 |
const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, |
--- |
| 341 |
bool OnlyExact = false); |
--- |
341 |
bool OnlyExact = false); |
--- |
| 342 |
|
--- |
342 |
|
--- |
| 343 |
/// Collect all potential values of the one stored by \p SI into |
--- |
343 |
/// Collect all potential values of the one stored by \p SI into |
--- |
| 344 |
/// \p PotentialCopies. That is, the only copies that were made via the |
--- |
344 |
/// \p PotentialCopies. That is, the only copies that were made via the |
--- |
| 345 |
/// store are assumed to be known and all are in \p PotentialCopies. Dependences |
--- |
345 |
/// store are assumed to be known and all are in \p PotentialCopies. Dependences |
--- |
| 346 |
/// onto \p QueryingAA are properly tracked, \p UsedAssumedInformation will |
--- |
346 |
/// onto \p QueryingAA are properly tracked, \p UsedAssumedInformation will |
--- |
| 347 |
/// inform the caller if assumed information was used. |
--- |
347 |
/// inform the caller if assumed information was used. |
--- |
| 348 |
/// |
--- |
348 |
/// |
--- |
| 349 |
/// \returns True if the assumed potential copies are all in \p PotentialCopies, |
--- |
349 |
/// \returns True if the assumed potential copies are all in \p PotentialCopies, |
--- |
| 350 |
/// false if something went wrong and the copies could not be |
--- |
350 |
/// false if something went wrong and the copies could not be |
--- |
| 351 |
/// determined. |
--- |
351 |
/// determined. |
--- |
| 352 |
bool getPotentialCopiesOfStoredValue( |
--- |
352 |
bool getPotentialCopiesOfStoredValue( |
--- |
| 353 |
Attributor &A, StoreInst &SI, SmallSetVector &PotentialCopies, |
--- |
353 |
Attributor &A, StoreInst &SI, SmallSetVector &PotentialCopies, |
--- |
| 354 |
const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, |
--- |
354 |
const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, |
--- |
| 355 |
bool OnlyExact = false); |
--- |
355 |
bool OnlyExact = false); |
--- |
| 356 |
|
--- |
356 |
|
--- |
| 357 |
/// Return true if \p IRP is readonly. This will query respective AAs that |
--- |
357 |
/// Return true if \p IRP is readonly. This will query respective AAs that |
--- |
| 358 |
/// deduce the information and introduce dependences for \p QueryingAA. |
--- |
358 |
/// deduce the information and introduce dependences for \p QueryingAA. |
--- |
| 359 |
bool isAssumedReadOnly(Attributor &A, const IRPosition &IRP, |
--- |
359 |
bool isAssumedReadOnly(Attributor &A, const IRPosition &IRP, |
--- |
| 360 |
const AbstractAttribute &QueryingAA, bool &IsKnown); |
--- |
360 |
const AbstractAttribute &QueryingAA, bool &IsKnown); |
--- |
| 361 |
|
--- |
361 |
|
--- |
| 362 |
/// Return true if \p IRP is readnone. This will query respective AAs that |
--- |
362 |
/// Return true if \p IRP is readnone. This will query respective AAs that |
--- |
| 363 |
/// deduce the information and introduce dependences for \p QueryingAA. |
--- |
363 |
/// deduce the information and introduce dependences for \p QueryingAA. |
--- |
| 364 |
bool isAssumedReadNone(Attributor &A, const IRPosition &IRP, |
--- |
364 |
bool isAssumedReadNone(Attributor &A, const IRPosition &IRP, |
--- |
| 365 |
const AbstractAttribute &QueryingAA, bool &IsKnown); |
--- |
365 |
const AbstractAttribute &QueryingAA, bool &IsKnown); |
--- |
| 366 |
|
--- |
366 |
|
--- |
| 367 |
/// Return true if \p ToI is potentially reachable from \p FromI without running |
--- |
367 |
/// Return true if \p ToI is potentially reachable from \p FromI without running |
--- |
| 368 |
/// into any instruction in \p ExclusionSet The two instructions do not need to |
--- |
368 |
/// into any instruction in \p ExclusionSet The two instructions do not need to |
--- |
| 369 |
/// be in the same function. \p GoBackwardsCB can be provided to convey domain |
--- |
369 |
/// be in the same function. \p GoBackwardsCB can be provided to convey domain |
--- |
| 370 |
/// knowledge about the "lifespan" the user is interested in. By default, the |
--- |
370 |
/// knowledge about the "lifespan" the user is interested in. By default, the |
--- |
| 371 |
/// callers of \p FromI are checked as well to determine if \p ToI can be |
--- |
371 |
/// callers of \p FromI are checked as well to determine if \p ToI can be |
--- |
| 372 |
/// reached. If the query is not interested in callers beyond a certain point, |
--- |
372 |
/// reached. If the query is not interested in callers beyond a certain point, |
--- |
| 373 |
/// e.g., a GPU kernel entry or the function containing an alloca, the |
--- |
373 |
/// e.g., a GPU kernel entry or the function containing an alloca, the |
--- |
| 374 |
/// \p GoBackwardsCB should return false. |
--- |
374 |
/// \p GoBackwardsCB should return false. |
--- |
| 375 |
bool isPotentiallyReachable( |
--- |
375 |
bool isPotentiallyReachable( |
--- |
| 376 |
Attributor &A, const Instruction &FromI, const Instruction &ToI, |
--- |
376 |
Attributor &A, const Instruction &FromI, const Instruction &ToI, |
--- |
| 377 |
const AbstractAttribute &QueryingAA, |
--- |
377 |
const AbstractAttribute &QueryingAA, |
--- |
| 378 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr, |
--- |
378 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr, |
--- |
| 379 |
std::function GoBackwardsCB = nullptr); |
--- |
379 |
std::function GoBackwardsCB = nullptr); |
--- |
| 380 |
|
--- |
380 |
|
--- |
| 381 |
/// Same as above but it is sufficient to reach any instruction in \p ToFn. |
--- |
381 |
/// Same as above but it is sufficient to reach any instruction in \p ToFn. |
--- |
| 382 |
bool isPotentiallyReachable( |
--- |
382 |
bool isPotentiallyReachable( |
--- |
| 383 |
Attributor &A, const Instruction &FromI, const Function &ToFn, |
--- |
383 |
Attributor &A, const Instruction &FromI, const Function &ToFn, |
--- |
| 384 |
const AbstractAttribute &QueryingAA, |
--- |
384 |
const AbstractAttribute &QueryingAA, |
--- |
| 385 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr, |
--- |
385 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr, |
--- |
| 386 |
std::function GoBackwardsCB = nullptr); |
--- |
386 |
std::function GoBackwardsCB = nullptr); |
--- |
| 387 |
|
--- |
387 |
|
--- |
| 388 |
/// Return true if \p Obj is assumed to be a thread local object. |
--- |
388 |
/// Return true if \p Obj is assumed to be a thread local object. |
--- |
| 389 |
bool isAssumedThreadLocalObject(Attributor &A, Value &Obj, |
--- |
389 |
bool isAssumedThreadLocalObject(Attributor &A, Value &Obj, |
--- |
| 390 |
const AbstractAttribute &QueryingAA); |
--- |
390 |
const AbstractAttribute &QueryingAA); |
--- |
| 391 |
|
--- |
391 |
|
--- |
| 392 |
/// Return true if \p I is potentially affected by a barrier. |
--- |
392 |
/// Return true if \p I is potentially affected by a barrier. |
--- |
| 393 |
bool isPotentiallyAffectedByBarrier(Attributor &A, const Instruction &I, |
--- |
393 |
bool isPotentiallyAffectedByBarrier(Attributor &A, const Instruction &I, |
--- |
| 394 |
const AbstractAttribute &QueryingAA); |
--- |
394 |
const AbstractAttribute &QueryingAA); |
--- |
| 395 |
bool isPotentiallyAffectedByBarrier(Attributor &A, ArrayRef Ptrs, |
--- |
395 |
bool isPotentiallyAffectedByBarrier(Attributor &A, ArrayRef Ptrs, |
--- |
| 396 |
const AbstractAttribute &QueryingAA, |
--- |
396 |
const AbstractAttribute &QueryingAA, |
--- |
| 397 |
const Instruction *CtxI); |
--- |
397 |
const Instruction *CtxI); |
--- |
| 398 |
} // namespace AA |
--- |
398 |
} // namespace AA |
--- |
| 399 |
|
--- |
399 |
|
--- |
| 400 |
template <> |
--- |
400 |
template <> |
--- |
| 401 |
struct DenseMapInfo |
--- |
401 |
struct DenseMapInfo |
--- |
| 402 |
: public DenseMapInfo { |
--- |
402 |
: public DenseMapInfo { |
--- |
| 403 |
using Base = DenseMapInfo; |
--- |
403 |
using Base = DenseMapInfo; |
--- |
| 404 |
static inline AA::ValueAndContext getEmptyKey() { |
--- |
404 |
static inline AA::ValueAndContext getEmptyKey() { |
--- |
| 405 |
return Base::getEmptyKey(); |
--- |
405 |
return Base::getEmptyKey(); |
--- |
| 406 |
} |
--- |
406 |
} |
--- |
| 407 |
static inline AA::ValueAndContext getTombstoneKey() { |
--- |
407 |
static inline AA::ValueAndContext getTombstoneKey() { |
--- |
| 408 |
return Base::getTombstoneKey(); |
--- |
408 |
return Base::getTombstoneKey(); |
--- |
| 409 |
} |
--- |
409 |
} |
--- |
| 410 |
static unsigned getHashValue(const AA::ValueAndContext &VAC) { |
--- |
410 |
static unsigned getHashValue(const AA::ValueAndContext &VAC) { |
--- |
| 411 |
return Base::getHashValue(VAC); |
--- |
411 |
return Base::getHashValue(VAC); |
--- |
| 412 |
} |
--- |
412 |
} |
--- |
| 413 |
|
--- |
413 |
|
--- |
| 414 |
static bool isEqual(const AA::ValueAndContext &LHS, |
--- |
414 |
static bool isEqual(const AA::ValueAndContext &LHS, |
--- |
| 415 |
const AA::ValueAndContext &RHS) { |
--- |
415 |
const AA::ValueAndContext &RHS) { |
--- |
| 416 |
return Base::isEqual(LHS, RHS); |
--- |
416 |
return Base::isEqual(LHS, RHS); |
--- |
| 417 |
} |
--- |
417 |
} |
--- |
| 418 |
}; |
--- |
418 |
}; |
--- |
| 419 |
|
--- |
419 |
|
--- |
| 420 |
template <> |
--- |
420 |
template <> |
--- |
| 421 |
struct DenseMapInfo : public DenseMapInfo { |
--- |
421 |
struct DenseMapInfo : public DenseMapInfo { |
--- |
| 422 |
using Base = DenseMapInfo; |
--- |
422 |
using Base = DenseMapInfo; |
--- |
| 423 |
static inline AA::ValueScope getEmptyKey() { |
--- |
423 |
static inline AA::ValueScope getEmptyKey() { |
--- |
| 424 |
return AA::ValueScope(Base::getEmptyKey()); |
--- |
424 |
return AA::ValueScope(Base::getEmptyKey()); |
--- |
| 425 |
} |
--- |
425 |
} |
--- |
| 426 |
static inline AA::ValueScope getTombstoneKey() { |
--- |
426 |
static inline AA::ValueScope getTombstoneKey() { |
--- |
| 427 |
return AA::ValueScope(Base::getTombstoneKey()); |
--- |
427 |
return AA::ValueScope(Base::getTombstoneKey()); |
--- |
| 428 |
} |
--- |
428 |
} |
--- |
| 429 |
static unsigned getHashValue(const AA::ValueScope &S) { |
--- |
429 |
static unsigned getHashValue(const AA::ValueScope &S) { |
--- |
| 430 |
return Base::getHashValue(S); |
--- |
430 |
return Base::getHashValue(S); |
--- |
| 431 |
} |
--- |
431 |
} |
--- |
| 432 |
|
--- |
432 |
|
--- |
| 433 |
static bool isEqual(const AA::ValueScope &LHS, const AA::ValueScope &RHS) { |
--- |
433 |
static bool isEqual(const AA::ValueScope &LHS, const AA::ValueScope &RHS) { |
--- |
| 434 |
return Base::isEqual(LHS, RHS); |
--- |
434 |
return Base::isEqual(LHS, RHS); |
--- |
| 435 |
} |
--- |
435 |
} |
--- |
| 436 |
}; |
--- |
436 |
}; |
--- |
| 437 |
|
--- |
437 |
|
--- |
| 438 |
template <> |
--- |
438 |
template <> |
--- |
| 439 |
struct DenseMapInfo |
--- |
439 |
struct DenseMapInfo |
--- |
| 440 |
: public DenseMapInfo { |
--- |
440 |
: public DenseMapInfo { |
--- |
| 441 |
using super = DenseMapInfo; |
--- |
441 |
using super = DenseMapInfo; |
--- |
| 442 |
static inline const AA::InstExclusionSetTy *getEmptyKey() { |
0 |
442 |
static inline const AA::InstExclusionSetTy *getEmptyKey() { |
0 |
| 443 |
return static_cast(super::getEmptyKey()); |
0 |
443 |
return static_cast(super::getEmptyKey()); |
0 |
| 444 |
} |
--- |
444 |
} |
--- |
| 445 |
static inline const AA::InstExclusionSetTy *getTombstoneKey() { |
0 |
445 |
static inline const AA::InstExclusionSetTy *getTombstoneKey() { |
0 |
| 446 |
return static_cast( |
--- |
446 |
return static_cast( |
--- |
| 447 |
super::getTombstoneKey()); |
0 |
447 |
super::getTombstoneKey()); |
0 |
| 448 |
} |
--- |
448 |
} |
--- |
| 449 |
static unsigned getHashValue(const AA::InstExclusionSetTy *BES) { |
--- |
449 |
static unsigned getHashValue(const AA::InstExclusionSetTy *BES) { |
--- |
| 450 |
unsigned H = 0; |
--- |
450 |
unsigned H = 0; |
--- |
| 451 |
if (BES) |
--- |
451 |
if (BES) |
--- |
| 452 |
for (const auto *II : *BES) |
--- |
452 |
for (const auto *II : *BES) |
--- |
| 453 |
H += DenseMapInfo::getHashValue(II); |
--- |
453 |
H += DenseMapInfo::getHashValue(II); |
--- |
| 454 |
return H; |
--- |
454 |
return H; |
--- |
| 455 |
} |
--- |
455 |
} |
--- |
| 456 |
static bool isEqual(const AA::InstExclusionSetTy *LHS, |
0 |
456 |
static bool isEqual(const AA::InstExclusionSetTy *LHS, |
0 |
| 457 |
const AA::InstExclusionSetTy *RHS) { |
--- |
457 |
const AA::InstExclusionSetTy *RHS) { |
--- |
| 458 |
if (LHS == RHS) |
0 |
458 |
if (LHS == RHS) |
0 |
| 459 |
return true; |
0 |
459 |
return true; |
0 |
| 460 |
if (LHS == getEmptyKey() || RHS == getEmptyKey() || |
0 |
460 |
if (LHS == getEmptyKey() || RHS == getEmptyKey() || |
0 |
| 461 |
LHS == getTombstoneKey() || RHS == getTombstoneKey()) |
0 |
461 |
LHS == getTombstoneKey() || RHS == getTombstoneKey()) |
0 |
| 462 |
return false; |
0 |
462 |
return false; |
0 |
| 463 |
auto SizeLHS = LHS ? LHS->size() : 0; |
0 |
463 |
auto SizeLHS = LHS ? LHS->size() : 0; |
0 |
| 464 |
auto SizeRHS = RHS ? RHS->size() : 0; |
0 |
464 |
auto SizeRHS = RHS ? RHS->size() : 0; |
0 |
| 465 |
if (SizeLHS != SizeRHS) |
0 |
465 |
if (SizeLHS != SizeRHS) |
0 |
| 466 |
return false; |
0 |
466 |
return false; |
0 |
| 467 |
if (SizeRHS == 0) |
0 |
467 |
if (SizeRHS == 0) |
0 |
| 468 |
return true; |
0 |
468 |
return true; |
0 |
| 469 |
return llvm::set_is_subset(*LHS, *RHS); |
0 |
469 |
return llvm::set_is_subset(*LHS, *RHS); |
0 |
| 470 |
} |
--- |
470 |
} |
--- |
| 471 |
}; |
--- |
471 |
}; |
--- |
| 472 |
|
--- |
472 |
|
--- |
| 473 |
/// The value passed to the line option that defines the maximal initialization |
--- |
473 |
/// The value passed to the line option that defines the maximal initialization |
--- |
| 474 |
/// chain length. |
--- |
474 |
/// chain length. |
--- |
| 475 |
extern unsigned MaxInitializationChainLength; |
--- |
475 |
extern unsigned MaxInitializationChainLength; |
--- |
| 476 |
|
--- |
476 |
|
--- |
| 477 |
///{ |
--- |
477 |
///{ |
--- |
| 478 |
enum class ChangeStatus { |
--- |
478 |
enum class ChangeStatus { |
--- |
| 479 |
CHANGED, |
--- |
479 |
CHANGED, |
--- |
| 480 |
UNCHANGED, |
--- |
480 |
UNCHANGED, |
--- |
| 481 |
}; |
--- |
481 |
}; |
--- |
| 482 |
|
--- |
482 |
|
--- |
| 483 |
ChangeStatus operator|(ChangeStatus l, ChangeStatus r); |
--- |
483 |
ChangeStatus operator|(ChangeStatus l, ChangeStatus r); |
--- |
| 484 |
ChangeStatus &operator|=(ChangeStatus &l, ChangeStatus r); |
--- |
484 |
ChangeStatus &operator|=(ChangeStatus &l, ChangeStatus r); |
--- |
| 485 |
ChangeStatus operator&(ChangeStatus l, ChangeStatus r); |
--- |
485 |
ChangeStatus operator&(ChangeStatus l, ChangeStatus r); |
--- |
| 486 |
ChangeStatus &operator&=(ChangeStatus &l, ChangeStatus r); |
--- |
486 |
ChangeStatus &operator&=(ChangeStatus &l, ChangeStatus r); |
--- |
| 487 |
|
--- |
487 |
|
--- |
| 488 |
enum class DepClassTy { |
--- |
488 |
enum class DepClassTy { |
--- |
| 489 |
REQUIRED, ///< The target cannot be valid if the source is not. |
--- |
489 |
REQUIRED, ///< The target cannot be valid if the source is not. |
--- |
| 490 |
OPTIONAL, ///< The target may be valid if the source is not. |
--- |
490 |
OPTIONAL, ///< The target may be valid if the source is not. |
--- |
| 491 |
NONE, ///< Do not track a dependence between source and target. |
--- |
491 |
NONE, ///< Do not track a dependence between source and target. |
--- |
| 492 |
}; |
--- |
492 |
}; |
--- |
| 493 |
///} |
--- |
493 |
///} |
--- |
| 494 |
|
--- |
494 |
|
--- |
| 495 |
/// The data structure for the nodes of a dependency graph |
--- |
495 |
/// The data structure for the nodes of a dependency graph |
--- |
| 496 |
struct AADepGraphNode { |
--- |
496 |
struct AADepGraphNode { |
--- |
| 497 |
public: |
--- |
497 |
public: |
--- |
| 498 |
virtual ~AADepGraphNode() = default; |
0 |
498 |
virtual ~AADepGraphNode() = default; |
0 |
| 499 |
using DepTy = PointerIntPair; |
--- |
499 |
using DepTy = PointerIntPair; |
--- |
| 500 |
using DepSetTy = SmallSetVector; |
--- |
500 |
using DepSetTy = SmallSetVector; |
--- |
| 501 |
|
--- |
501 |
|
--- |
| 502 |
protected: |
--- |
502 |
protected: |
--- |
| 503 |
/// Set of dependency graph nodes which should be updated if this one |
--- |
503 |
/// Set of dependency graph nodes which should be updated if this one |
--- |
| 504 |
/// is updated. The bit encodes if it is optional. |
--- |
504 |
/// is updated. The bit encodes if it is optional. |
--- |
| 505 |
DepSetTy Deps; |
--- |
505 |
DepSetTy Deps; |
--- |
| 506 |
|
--- |
506 |
|
--- |
| 507 |
static AADepGraphNode *DepGetVal(const DepTy &DT) { return DT.getPointer(); } |
0 |
507 |
static AADepGraphNode *DepGetVal(const DepTy &DT) { return DT.getPointer(); } |
0 |
| 508 |
static AbstractAttribute *DepGetValAA(const DepTy &DT) { |
0 |
508 |
static AbstractAttribute *DepGetValAA(const DepTy &DT) { |
0 |
| 509 |
return cast(DT.getPointer()); |
0 |
509 |
return cast(DT.getPointer()); |
0 |
| 510 |
} |
--- |
510 |
} |
--- |
| 511 |
|
--- |
511 |
|
--- |
| 512 |
operator AbstractAttribute *() { return cast(this); } |
--- |
512 |
operator AbstractAttribute *() { return cast(this); } |
--- |
| 513 |
|
--- |
513 |
|
--- |
| 514 |
public: |
--- |
514 |
public: |
--- |
| 515 |
using iterator = mapped_iterator; |
--- |
515 |
using iterator = mapped_iterator; |
--- |
| 516 |
using aaiterator = |
--- |
516 |
using aaiterator = |
--- |
| 517 |
mapped_iterator; |
--- |
517 |
mapped_iterator; |
--- |
| 518 |
|
--- |
518 |
|
--- |
| 519 |
aaiterator begin() { return aaiterator(Deps.begin(), &DepGetValAA); } |
0 |
519 |
aaiterator begin() { return aaiterator(Deps.begin(), &DepGetValAA); } |
0 |
| 520 |
aaiterator end() { return aaiterator(Deps.end(), &DepGetValAA); } |
0 |
520 |
aaiterator end() { return aaiterator(Deps.end(), &DepGetValAA); } |
0 |
| 521 |
iterator child_begin() { return iterator(Deps.begin(), &DepGetVal); } |
0 |
521 |
iterator child_begin() { return iterator(Deps.begin(), &DepGetVal); } |
0 |
| 522 |
iterator child_end() { return iterator(Deps.end(), &DepGetVal); } |
0 |
522 |
iterator child_end() { return iterator(Deps.end(), &DepGetVal); } |
0 |
| 523 |
|
--- |
523 |
|
--- |
| 524 |
void print(raw_ostream &OS) const { print(nullptr, OS); } |
0 |
524 |
void print(raw_ostream &OS) const { print(nullptr, OS); } |
0 |
| 525 |
virtual void print(Attributor *, raw_ostream &OS) const { |
0 |
525 |
virtual void print(Attributor *, raw_ostream &OS) const { |
0 |
| 526 |
OS << "AADepNode Impl\n"; |
0 |
526 |
OS << "AADepNode Impl\n"; |
0 |
| 527 |
} |
0 |
527 |
} |
0 |
| 528 |
DepSetTy &getDeps() { return Deps; } |
--- |
528 |
DepSetTy &getDeps() { return Deps; } |
--- |
| 529 |
|
--- |
529 |
|
--- |
| 530 |
friend struct Attributor; |
--- |
530 |
friend struct Attributor; |
--- |
| 531 |
friend struct AADepGraph; |
--- |
531 |
friend struct AADepGraph; |
--- |
| 532 |
}; |
--- |
532 |
}; |
--- |
| 533 |
|
--- |
533 |
|
--- |
| 534 |
/// The data structure for the dependency graph |
--- |
534 |
/// The data structure for the dependency graph |
--- |
| 535 |
/// |
--- |
535 |
/// |
--- |
| 536 |
/// Note that in this graph if there is an edge from A to B (A -> B), |
--- |
536 |
/// Note that in this graph if there is an edge from A to B (A -> B), |
--- |
| 537 |
/// then it means that B depends on A, and when the state of A is |
--- |
537 |
/// then it means that B depends on A, and when the state of A is |
--- |
| 538 |
/// updated, node B should also be updated |
--- |
538 |
/// updated, node B should also be updated |
--- |
| 539 |
struct AADepGraph { |
--- |
539 |
struct AADepGraph { |
--- |
| 540 |
AADepGraph() = default; |
0 |
540 |
AADepGraph() = default; |
0 |
| 541 |
~AADepGraph() = default; |
0 |
541 |
~AADepGraph() = default; |
0 |
| 542 |
|
--- |
542 |
|
--- |
| 543 |
using DepTy = AADepGraphNode::DepTy; |
--- |
543 |
using DepTy = AADepGraphNode::DepTy; |
--- |
| 544 |
static AADepGraphNode *DepGetVal(const DepTy &DT) { return DT.getPointer(); } |
--- |
544 |
static AADepGraphNode *DepGetVal(const DepTy &DT) { return DT.getPointer(); } |
--- |
| 545 |
using iterator = |
--- |
545 |
using iterator = |
--- |
| 546 |
mapped_iterator; |
--- |
546 |
mapped_iterator; |
--- |
| 547 |
|
--- |
547 |
|
--- |
| 548 |
/// There is no root node for the dependency graph. But the SCCIterator |
--- |
548 |
/// There is no root node for the dependency graph. But the SCCIterator |
--- |
| 549 |
/// requires a single entry point, so we maintain a fake("synthetic") root |
--- |
549 |
/// requires a single entry point, so we maintain a fake("synthetic") root |
--- |
| 550 |
/// node that depends on every node. |
--- |
550 |
/// node that depends on every node. |
--- |
| 551 |
AADepGraphNode SyntheticRoot; |
--- |
551 |
AADepGraphNode SyntheticRoot; |
--- |
| 552 |
AADepGraphNode *GetEntryNode() { return &SyntheticRoot; } |
--- |
552 |
AADepGraphNode *GetEntryNode() { return &SyntheticRoot; } |
--- |
| 553 |
|
--- |
553 |
|
--- |
| 554 |
iterator begin() { return SyntheticRoot.child_begin(); } |
0 |
554 |
iterator begin() { return SyntheticRoot.child_begin(); } |
0 |
| 555 |
iterator end() { return SyntheticRoot.child_end(); } |
0 |
555 |
iterator end() { return SyntheticRoot.child_end(); } |
0 |
| 556 |
|
--- |
556 |
|
--- |
| 557 |
void viewGraph(); |
--- |
557 |
void viewGraph(); |
--- |
| 558 |
|
--- |
558 |
|
--- |
| 559 |
/// Dump graph to file |
--- |
559 |
/// Dump graph to file |
--- |
| 560 |
void dumpGraph(); |
--- |
560 |
void dumpGraph(); |
--- |
| 561 |
|
--- |
561 |
|
--- |
| 562 |
/// Print dependency graph |
--- |
562 |
/// Print dependency graph |
--- |
| 563 |
void print(); |
--- |
563 |
void print(); |
--- |
| 564 |
}; |
--- |
564 |
}; |
--- |
| 565 |
|
--- |
565 |
|
--- |
| 566 |
/// Helper to describe and deal with positions in the LLVM-IR. |
--- |
566 |
/// Helper to describe and deal with positions in the LLVM-IR. |
--- |
| 567 |
/// |
--- |
567 |
/// |
--- |
| 568 |
/// A position in the IR is described by an anchor value and an "offset" that |
--- |
568 |
/// A position in the IR is described by an anchor value and an "offset" that |
--- |
| 569 |
/// could be the argument number, for call sites and arguments, or an indicator |
--- |
569 |
/// could be the argument number, for call sites and arguments, or an indicator |
--- |
| 570 |
/// of the "position kind". The kinds, specified in the Kind enum below, include |
--- |
570 |
/// of the "position kind". The kinds, specified in the Kind enum below, include |
--- |
| 571 |
/// the locations in the attribute list, i.a., function scope and return value, |
--- |
571 |
/// the locations in the attribute list, i.a., function scope and return value, |
--- |
| 572 |
/// as well as a distinction between call sites and functions. Finally, there |
--- |
572 |
/// as well as a distinction between call sites and functions. Finally, there |
--- |
| 573 |
/// are floating values that do not have a corresponding attribute list |
--- |
573 |
/// are floating values that do not have a corresponding attribute list |
--- |
| 574 |
/// position. |
--- |
574 |
/// position. |
--- |
| 575 |
struct IRPosition { |
--- |
575 |
struct IRPosition { |
--- |
| 576 |
// NOTE: In the future this definition can be changed to support recursive |
--- |
576 |
// NOTE: In the future this definition can be changed to support recursive |
--- |
| 577 |
// functions. |
--- |
577 |
// functions. |
--- |
| 578 |
using CallBaseContext = CallBase; |
--- |
578 |
using CallBaseContext = CallBase; |
--- |
| 579 |
|
--- |
579 |
|
--- |
| 580 |
/// The positions we distinguish in the IR. |
--- |
580 |
/// The positions we distinguish in the IR. |
--- |
| 581 |
enum Kind : char { |
--- |
581 |
enum Kind : char { |
--- |
| 582 |
IRP_INVALID, ///< An invalid position. |
--- |
582 |
IRP_INVALID, ///< An invalid position. |
--- |
| 583 |
IRP_FLOAT, ///< A position that is not associated with a spot suitable |
--- |
583 |
IRP_FLOAT, ///< A position that is not associated with a spot suitable |
--- |
| 584 |
///< for attributes. This could be any value or instruction. |
--- |
584 |
///< for attributes. This could be any value or instruction. |
--- |
| 585 |
IRP_RETURNED, ///< An attribute for the function return value. |
--- |
585 |
IRP_RETURNED, ///< An attribute for the function return value. |
--- |
| 586 |
IRP_CALL_SITE_RETURNED, ///< An attribute for a call site return value. |
--- |
586 |
IRP_CALL_SITE_RETURNED, ///< An attribute for a call site return value. |
--- |
| 587 |
IRP_FUNCTION, ///< An attribute for a function (scope). |
--- |
587 |
IRP_FUNCTION, ///< An attribute for a function (scope). |
--- |
| 588 |
IRP_CALL_SITE, ///< An attribute for a call site (function scope). |
--- |
588 |
IRP_CALL_SITE, ///< An attribute for a call site (function scope). |
--- |
| 589 |
IRP_ARGUMENT, ///< An attribute for a function argument. |
--- |
589 |
IRP_ARGUMENT, ///< An attribute for a function argument. |
--- |
| 590 |
IRP_CALL_SITE_ARGUMENT, ///< An attribute for a call site argument. |
--- |
590 |
IRP_CALL_SITE_ARGUMENT, ///< An attribute for a call site argument. |
--- |
| 591 |
}; |
--- |
591 |
}; |
--- |
| 592 |
|
--- |
592 |
|
--- |
| 593 |
/// Default constructor available to create invalid positions implicitly. All |
--- |
593 |
/// Default constructor available to create invalid positions implicitly. All |
--- |
| 594 |
/// other positions need to be created explicitly through the appropriate |
--- |
594 |
/// other positions need to be created explicitly through the appropriate |
--- |
| 595 |
/// static member function. |
--- |
595 |
/// static member function. |
--- |
| 596 |
IRPosition() : Enc(nullptr, ENC_VALUE) { verify(); } |
--- |
596 |
IRPosition() : Enc(nullptr, ENC_VALUE) { verify(); } |
--- |
| 597 |
|
--- |
597 |
|
--- |
| 598 |
/// Create a position describing the value of \p V. |
--- |
598 |
/// Create a position describing the value of \p V. |
--- |
| 599 |
static const IRPosition value(const Value &V, |
0 |
599 |
static const IRPosition value(const Value &V, |
0 |
| 600 |
const CallBaseContext *CBContext = nullptr) { |
--- |
600 |
const CallBaseContext *CBContext = nullptr) { |
--- |
| 601 |
if (auto *Arg = dyn_cast(&V)) |
0 |
601 |
if (auto *Arg = dyn_cast(&V)) |
0 |
| 602 |
return IRPosition::argument(*Arg, CBContext); |
0 |
602 |
return IRPosition::argument(*Arg, CBContext); |
0 |
| 603 |
if (auto *CB = dyn_cast(&V)) |
0 |
603 |
if (auto *CB = dyn_cast(&V)) |
0 |
| 604 |
return IRPosition::callsite_returned(*CB); |
0 |
604 |
return IRPosition::callsite_returned(*CB); |
0 |
| 605 |
return IRPosition(const_cast(V), IRP_FLOAT, CBContext); |
0 |
605 |
return IRPosition(const_cast(V), IRP_FLOAT, CBContext); |
0 |
| 606 |
} |
--- |
606 |
} |
--- |
| 607 |
|
--- |
607 |
|
--- |
| 608 |
/// Create a position describing the instruction \p I. This is different from |
--- |
608 |
/// Create a position describing the instruction \p I. This is different from |
--- |
| 609 |
/// the value version because call sites are treated as intrusctions rather |
--- |
609 |
/// the value version because call sites are treated as intrusctions rather |
--- |
| 610 |
/// than their return value in this function. |
--- |
610 |
/// than their return value in this function. |
--- |
| 611 |
static const IRPosition inst(const Instruction &I, |
0 |
611 |
static const IRPosition inst(const Instruction &I, |
0 |
| 612 |
const CallBaseContext *CBContext = nullptr) { |
--- |
612 |
const CallBaseContext *CBContext = nullptr) { |
--- |
| 613 |
return IRPosition(const_cast(I), IRP_FLOAT, CBContext); |
0 |
613 |
return IRPosition(const_cast(I), IRP_FLOAT, CBContext); |
0 |
| 614 |
} |
--- |
614 |
} |
--- |
| 615 |
|
--- |
615 |
|
--- |
| 616 |
/// Create a position describing the function scope of \p F. |
--- |
616 |
/// Create a position describing the function scope of \p F. |
--- |
| 617 |
/// \p CBContext is used for call base specific analysis. |
--- |
617 |
/// \p CBContext is used for call base specific analysis. |
--- |
| 618 |
static const IRPosition function(const Function &F, |
0 |
618 |
static const IRPosition function(const Function &F, |
0 |
| 619 |
const CallBaseContext *CBContext = nullptr) { |
--- |
619 |
const CallBaseContext *CBContext = nullptr) { |
--- |
| 620 |
return IRPosition(const_cast(F), IRP_FUNCTION, CBContext); |
0 |
620 |
return IRPosition(const_cast(F), IRP_FUNCTION, CBContext); |
0 |
| 621 |
} |
--- |
621 |
} |
--- |
| 622 |
|
--- |
622 |
|
--- |
| 623 |
/// Create a position describing the returned value of \p F. |
--- |
623 |
/// Create a position describing the returned value of \p F. |
--- |
| 624 |
/// \p CBContext is used for call base specific analysis. |
--- |
624 |
/// \p CBContext is used for call base specific analysis. |
--- |
| 625 |
static const IRPosition returned(const Function &F, |
0 |
625 |
static const IRPosition returned(const Function &F, |
0 |
| 626 |
const CallBaseContext *CBContext = nullptr) { |
--- |
626 |
const CallBaseContext *CBContext = nullptr) { |
--- |
| 627 |
return IRPosition(const_cast(F), IRP_RETURNED, CBContext); |
0 |
627 |
return IRPosition(const_cast(F), IRP_RETURNED, CBContext); |
0 |
| 628 |
} |
--- |
628 |
} |
--- |
| 629 |
|
--- |
629 |
|
--- |
| 630 |
/// Create a position describing the argument \p Arg. |
--- |
630 |
/// Create a position describing the argument \p Arg. |
--- |
| 631 |
/// \p CBContext is used for call base specific analysis. |
--- |
631 |
/// \p CBContext is used for call base specific analysis. |
--- |
| 632 |
static const IRPosition argument(const Argument &Arg, |
0 |
632 |
static const IRPosition argument(const Argument &Arg, |
0 |
| 633 |
const CallBaseContext *CBContext = nullptr) { |
--- |
633 |
const CallBaseContext *CBContext = nullptr) { |
--- |
| 634 |
return IRPosition(const_cast(Arg), IRP_ARGUMENT, CBContext); |
0 |
634 |
return IRPosition(const_cast(Arg), IRP_ARGUMENT, CBContext); |
0 |
| 635 |
} |
--- |
635 |
} |
--- |
| 636 |
|
--- |
636 |
|
--- |
| 637 |
/// Create a position describing the function scope of \p CB. |
--- |
637 |
/// Create a position describing the function scope of \p CB. |
--- |
| 638 |
static const IRPosition callsite_function(const CallBase &CB) { |
0 |
638 |
static const IRPosition callsite_function(const CallBase &CB) { |
0 |
| 639 |
return IRPosition(const_cast(CB), IRP_CALL_SITE); |
0 |
639 |
return IRPosition(const_cast(CB), IRP_CALL_SITE); |
0 |
| 640 |
} |
--- |
640 |
} |
--- |
| 641 |
|
--- |
641 |
|
--- |
| 642 |
/// Create a position describing the returned value of \p CB. |
--- |
642 |
/// Create a position describing the returned value of \p CB. |
--- |
| 643 |
static const IRPosition callsite_returned(const CallBase &CB) { |
0 |
643 |
static const IRPosition callsite_returned(const CallBase &CB) { |
0 |
| 644 |
return IRPosition(const_cast(CB), IRP_CALL_SITE_RETURNED); |
0 |
644 |
return IRPosition(const_cast(CB), IRP_CALL_SITE_RETURNED); |
0 |
| 645 |
} |
--- |
645 |
} |
--- |
| 646 |
|
--- |
646 |
|
--- |
| 647 |
/// Create a position describing the argument of \p CB at position \p ArgNo. |
--- |
647 |
/// Create a position describing the argument of \p CB at position \p ArgNo. |
--- |
| 648 |
static const IRPosition callsite_argument(const CallBase &CB, |
0 |
648 |
static const IRPosition callsite_argument(const CallBase &CB, |
0 |
| 649 |
unsigned ArgNo) { |
--- |
649 |
unsigned ArgNo) { |
--- |
| 650 |
return IRPosition(const_cast |
0 |
650 |
return IRPosition(const_cast |
0 |
| 651 |
IRP_CALL_SITE_ARGUMENT); |
0 |
651 |
IRP_CALL_SITE_ARGUMENT); |
0 |
| 652 |
} |
--- |
652 |
} |
--- |
| 653 |
|
--- |
653 |
|
--- |
| 654 |
/// Create a position describing the argument of \p ACS at position \p ArgNo. |
--- |
654 |
/// Create a position describing the argument of \p ACS at position \p ArgNo. |
--- |
| 655 |
static const IRPosition callsite_argument(AbstractCallSite ACS, |
--- |
655 |
static const IRPosition callsite_argument(AbstractCallSite ACS, |
--- |
| 656 |
unsigned ArgNo) { |
--- |
656 |
unsigned ArgNo) { |
--- |
| 657 |
if (ACS.getNumArgOperands() <= ArgNo) |
--- |
657 |
if (ACS.getNumArgOperands() <= ArgNo) |
--- |
| 658 |
return IRPosition(); |
--- |
658 |
return IRPosition(); |
--- |
| 659 |
int CSArgNo = ACS.getCallArgOperandNo(ArgNo); |
--- |
659 |
int CSArgNo = ACS.getCallArgOperandNo(ArgNo); |
--- |
| 660 |
if (CSArgNo >= 0) |
--- |
660 |
if (CSArgNo >= 0) |
--- |
| 661 |
return IRPosition::callsite_argument( |
--- |
661 |
return IRPosition::callsite_argument( |
--- |
| 662 |
cast(*ACS.getInstruction()), CSArgNo); |
--- |
662 |
cast(*ACS.getInstruction()), CSArgNo); |
--- |
| 663 |
return IRPosition(); |
--- |
663 |
return IRPosition(); |
--- |
| 664 |
} |
--- |
664 |
} |
--- |
| 665 |
|
--- |
665 |
|
--- |
| 666 |
/// Create a position with function scope matching the "context" of \p IRP. |
--- |
666 |
/// Create a position with function scope matching the "context" of \p IRP. |
--- |
| 667 |
/// If \p IRP is a call site (see isAnyCallSitePosition()) then the result |
--- |
667 |
/// If \p IRP is a call site (see isAnyCallSitePosition()) then the result |
--- |
| 668 |
/// will be a call site position, otherwise the function position of the |
--- |
668 |
/// will be a call site position, otherwise the function position of the |
--- |
| 669 |
/// associated function. |
--- |
669 |
/// associated function. |
--- |
| 670 |
static const IRPosition |
--- |
670 |
static const IRPosition |
--- |
| 671 |
function_scope(const IRPosition &IRP, |
--- |
671 |
function_scope(const IRPosition &IRP, |
--- |
| 672 |
const CallBaseContext *CBContext = nullptr) { |
--- |
672 |
const CallBaseContext *CBContext = nullptr) { |
--- |
| 673 |
if (IRP.isAnyCallSitePosition()) { |
--- |
673 |
if (IRP.isAnyCallSitePosition()) { |
--- |
| 674 |
return IRPosition::callsite_function( |
--- |
674 |
return IRPosition::callsite_function( |
--- |
| 675 |
cast(IRP.getAnchorValue())); |
--- |
675 |
cast(IRP.getAnchorValue())); |
--- |
| 676 |
} |
--- |
676 |
} |
--- |
| 677 |
assert(IRP.getAssociatedFunction()); |
--- |
677 |
assert(IRP.getAssociatedFunction()); |
--- |
| 678 |
return IRPosition::function(*IRP.getAssociatedFunction(), CBContext); |
--- |
678 |
return IRPosition::function(*IRP.getAssociatedFunction(), CBContext); |
--- |
| 679 |
} |
--- |
679 |
} |
--- |
| 680 |
|
--- |
680 |
|
--- |
| 681 |
bool operator==(const IRPosition &RHS) const { |
0 |
681 |
bool operator==(const IRPosition &RHS) const { |
0 |
| 682 |
return Enc == RHS.Enc && RHS.CBContext == CBContext; |
0 |
682 |
return Enc == RHS.Enc && RHS.CBContext == CBContext; |
0 |
| 683 |
} |
--- |
683 |
} |
--- |
| 684 |
bool operator!=(const IRPosition &RHS) const { return !(*this == RHS); } |
--- |
684 |
bool operator!=(const IRPosition &RHS) const { return !(*this == RHS); } |
--- |
| 685 |
|
--- |
685 |
|
--- |
| 686 |
/// Return the value this abstract attribute is anchored with. |
--- |
686 |
/// Return the value this abstract attribute is anchored with. |
--- |
| 687 |
/// |
--- |
687 |
/// |
--- |
| 688 |
/// The anchor value might not be the associated value if the latter is not |
--- |
688 |
/// The anchor value might not be the associated value if the latter is not |
--- |
| 689 |
/// sufficient to determine where arguments will be manifested. This is, so |
--- |
689 |
/// sufficient to determine where arguments will be manifested. This is, so |
--- |
| 690 |
/// far, only the case for call site arguments as the value is not sufficient |
--- |
690 |
/// far, only the case for call site arguments as the value is not sufficient |
--- |
| 691 |
/// to pinpoint them. Instead, we can use the call site as an anchor. |
--- |
691 |
/// to pinpoint them. Instead, we can use the call site as an anchor. |
--- |
| 692 |
Value &getAnchorValue() const { |
0 |
692 |
Value &getAnchorValue() const { |
0 |
| 693 |
switch (getEncodingBits()) { |
0 |
693 |
switch (getEncodingBits()) { |
0 |
| 694 |
case ENC_VALUE: |
0 |
694 |
case ENC_VALUE: |
0 |
| 695 |
case ENC_RETURNED_VALUE: |
--- |
695 |
case ENC_RETURNED_VALUE: |
--- |
| 696 |
case ENC_FLOATING_FUNCTION: |
--- |
696 |
case ENC_FLOATING_FUNCTION: |
--- |
| 697 |
return *getAsValuePtr(); |
0 |
697 |
return *getAsValuePtr(); |
0 |
| 698 |
case ENC_CALL_SITE_ARGUMENT_USE: |
0 |
698 |
case ENC_CALL_SITE_ARGUMENT_USE: |
0 |
| 699 |
return *(getAsUsePtr()->getUser()); |
0 |
699 |
return *(getAsUsePtr()->getUser()); |
0 |
| 700 |
default: |
0 |
700 |
default: |
0 |
| 701 |
llvm_unreachable("Unkown encoding!"); |
0 |
701 |
llvm_unreachable("Unkown encoding!"); |
0 |
| 702 |
}; |
--- |
702 |
}; |
--- |
| 703 |
} |
--- |
703 |
} |
--- |
| 704 |
|
--- |
704 |
|
--- |
| 705 |
/// Return the associated function, if any. |
--- |
705 |
/// Return the associated function, if any. |
--- |
| 706 |
Function *getAssociatedFunction() const { |
0 |
706 |
Function *getAssociatedFunction() const { |
0 |
| 707 |
if (auto *CB = dyn_cast(&getAnchorValue())) { |
0 |
707 |
if (auto *CB = dyn_cast(&getAnchorValue())) { |
0 |
| 708 |
// We reuse the logic that associates callback calles to arguments of a |
--- |
708 |
// We reuse the logic that associates callback calles to arguments of a |
--- |
| 709 |
// call site here to identify the callback callee as the associated |
--- |
709 |
// call site here to identify the callback callee as the associated |
--- |
| 710 |
// function. |
--- |
710 |
// function. |
--- |
| 711 |
if (Argument *Arg = getAssociatedArgument()) |
0 |
711 |
if (Argument *Arg = getAssociatedArgument()) |
0 |
| 712 |
return Arg->getParent(); |
0 |
712 |
return Arg->getParent(); |
0 |
| 713 |
return dyn_cast_if_present( |
0 |
713 |
return dyn_cast_if_present( |
0 |
| 714 |
CB->getCalledOperand()->stripPointerCasts()); |
0 |
714 |
CB->getCalledOperand()->stripPointerCasts()); |
0 |
| 715 |
} |
--- |
715 |
} |
--- |
| 716 |
return getAnchorScope(); |
0 |
716 |
return getAnchorScope(); |
0 |
| 717 |
} |
--- |
717 |
} |
--- |
| 718 |
|
--- |
718 |
|
--- |
| 719 |
/// Return the associated argument, if any. |
--- |
719 |
/// Return the associated argument, if any. |
--- |
| 720 |
Argument *getAssociatedArgument() const; |
--- |
720 |
Argument *getAssociatedArgument() const; |
--- |
| 721 |
|
--- |
721 |
|
--- |
| 722 |
/// Return true if the position refers to a function interface, that is the |
--- |
722 |
/// Return true if the position refers to a function interface, that is the |
--- |
| 723 |
/// function scope, the function return, or an argument. |
--- |
723 |
/// function scope, the function return, or an argument. |
--- |
| 724 |
bool isFnInterfaceKind() const { |
0 |
724 |
bool isFnInterfaceKind() const { |
0 |
| 725 |
switch (getPositionKind()) { |
0 |
725 |
switch (getPositionKind()) { |
0 |
| 726 |
case IRPosition::IRP_FUNCTION: |
0 |
726 |
case IRPosition::IRP_FUNCTION: |
0 |
| 727 |
case IRPosition::IRP_RETURNED: |
--- |
727 |
case IRPosition::IRP_RETURNED: |
--- |
| 728 |
case IRPosition::IRP_ARGUMENT: |
--- |
728 |
case IRPosition::IRP_ARGUMENT: |
--- |
| 729 |
return true; |
0 |
729 |
return true; |
0 |
| 730 |
default: |
0 |
730 |
default: |
0 |
| 731 |
return false; |
0 |
731 |
return false; |
0 |
| 732 |
} |
--- |
732 |
} |
--- |
| 733 |
} |
--- |
733 |
} |
--- |
| 734 |
|
--- |
734 |
|
--- |
| 735 |
/// Return true if this is a function or call site position. |
--- |
735 |
/// Return true if this is a function or call site position. |
--- |
| 736 |
bool isFunctionScope() const { |
0 |
736 |
bool isFunctionScope() const { |
0 |
| 737 |
switch (getPositionKind()) { |
0 |
737 |
switch (getPositionKind()) { |
0 |
| 738 |
case IRPosition::IRP_CALL_SITE: |
0 |
738 |
case IRPosition::IRP_CALL_SITE: |
0 |
| 739 |
case IRPosition::IRP_FUNCTION: |
--- |
739 |
case IRPosition::IRP_FUNCTION: |
--- |
| 740 |
return true; |
0 |
740 |
return true; |
0 |
| 741 |
default: |
0 |
741 |
default: |
0 |
| 742 |
return false; |
0 |
742 |
return false; |
0 |
| 743 |
}; |
--- |
743 |
}; |
--- |
| 744 |
} |
--- |
744 |
} |
--- |
| 745 |
|
--- |
745 |
|
--- |
| 746 |
/// Return the Function surrounding the anchor value. |
--- |
746 |
/// Return the Function surrounding the anchor value. |
--- |
| 747 |
Function *getAnchorScope() const { |
0 |
747 |
Function *getAnchorScope() const { |
0 |
| 748 |
Value &V = getAnchorValue(); |
0 |
748 |
Value &V = getAnchorValue(); |
0 |
| 749 |
if (isa(V)) |
0 |
749 |
if (isa(V)) |
0 |
| 750 |
return &cast(V); |
0 |
750 |
return &cast(V); |
0 |
| 751 |
if (isa(V)) |
0 |
751 |
if (isa(V)) |
0 |
| 752 |
return cast(V).getParent(); |
0 |
752 |
return cast(V).getParent(); |
0 |
| 753 |
if (isa(V)) |
0 |
753 |
if (isa(V)) |
0 |
| 754 |
return cast(V).getFunction(); |
0 |
754 |
return cast(V).getFunction(); |
0 |
| 755 |
return nullptr; |
0 |
755 |
return nullptr; |
0 |
| 756 |
} |
--- |
756 |
} |
--- |
| 757 |
|
--- |
757 |
|
--- |
| 758 |
/// Return the context instruction, if any. |
--- |
758 |
/// Return the context instruction, if any. |
--- |
| 759 |
Instruction *getCtxI() const { |
0 |
759 |
Instruction *getCtxI() const { |
0 |
| 760 |
Value &V = getAnchorValue(); |
0 |
760 |
Value &V = getAnchorValue(); |
0 |
| 761 |
if (auto *I = dyn_cast(&V)) |
0 |
761 |
if (auto *I = dyn_cast(&V)) |
0 |
| 762 |
return I; |
0 |
762 |
return I; |
0 |
| 763 |
if (auto *Arg = dyn_cast(&V)) |
0 |
763 |
if (auto *Arg = dyn_cast(&V)) |
0 |
| 764 |
if (!Arg->getParent()->isDeclaration()) |
0 |
764 |
if (!Arg->getParent()->isDeclaration()) |
0 |
| 765 |
return &Arg->getParent()->getEntryBlock().front(); |
0 |
765 |
return &Arg->getParent()->getEntryBlock().front(); |
0 |
| 766 |
if (auto *F = dyn_cast(&V)) |
0 |
766 |
if (auto *F = dyn_cast(&V)) |
0 |
| 767 |
if (!F->isDeclaration()) |
0 |
767 |
if (!F->isDeclaration()) |
0 |
| 768 |
return &(F->getEntryBlock().front()); |
0 |
768 |
return &(F->getEntryBlock().front()); |
0 |
| 769 |
return nullptr; |
0 |
769 |
return nullptr; |
0 |
| 770 |
} |
--- |
770 |
} |
--- |
| 771 |
|
--- |
771 |
|
--- |
| 772 |
/// Return the value this abstract attribute is associated with. |
--- |
772 |
/// Return the value this abstract attribute is associated with. |
--- |
| 773 |
Value &getAssociatedValue() const { |
0 |
773 |
Value &getAssociatedValue() const { |
0 |
| 774 |
if (getCallSiteArgNo() < 0 || isa(&getAnchorValue())) |
0 |
774 |
if (getCallSiteArgNo() < 0 || isa(&getAnchorValue())) |
0 |
| 775 |
return getAnchorValue(); |
0 |
775 |
return getAnchorValue(); |
0 |
| 776 |
assert(isa(&getAnchorValue()) && "Expected a call base!"); |
0 |
776 |
assert(isa(&getAnchorValue()) && "Expected a call base!"); |
0 |
| 777 |
return *cast(&getAnchorValue()) |
0 |
777 |
return *cast(&getAnchorValue()) |
0 |
| 778 |
->getArgOperand(getCallSiteArgNo()); |
0 |
778 |
->getArgOperand(getCallSiteArgNo()); |
0 |
| 779 |
} |
--- |
779 |
} |
--- |
| 780 |
|
--- |
780 |
|
--- |
| 781 |
/// Return the type this abstract attribute is associated with. |
--- |
781 |
/// Return the type this abstract attribute is associated with. |
--- |
| 782 |
Type *getAssociatedType() const { |
0 |
782 |
Type *getAssociatedType() const { |
0 |
| 783 |
if (getPositionKind() == IRPosition::IRP_RETURNED) |
0 |
783 |
if (getPositionKind() == IRPosition::IRP_RETURNED) |
0 |
| 784 |
return getAssociatedFunction()->getReturnType(); |
0 |
784 |
return getAssociatedFunction()->getReturnType(); |
0 |
| 785 |
return getAssociatedValue().getType(); |
0 |
785 |
return getAssociatedValue().getType(); |
0 |
| 786 |
} |
--- |
786 |
} |
--- |
| 787 |
|
--- |
787 |
|
--- |
| 788 |
/// Return the callee argument number of the associated value if it is an |
--- |
788 |
/// Return the callee argument number of the associated value if it is an |
--- |
| 789 |
/// argument or call site argument, otherwise a negative value. In contrast to |
--- |
789 |
/// argument or call site argument, otherwise a negative value. In contrast to |
--- |
| 790 |
/// `getCallSiteArgNo` this method will always return the "argument number" |
--- |
790 |
/// `getCallSiteArgNo` this method will always return the "argument number" |
--- |
| 791 |
/// from the perspective of the callee. This may not the same as the call site |
--- |
791 |
/// from the perspective of the callee. This may not the same as the call site |
--- |
| 792 |
/// if this is a callback call. |
--- |
792 |
/// if this is a callback call. |
--- |
| 793 |
int getCalleeArgNo() const { |
0 |
793 |
int getCalleeArgNo() const { |
0 |
| 794 |
return getArgNo(/* CallbackCalleeArgIfApplicable */ true); |
0 |
794 |
return getArgNo(/* CallbackCalleeArgIfApplicable */ true); |
0 |
| 795 |
} |
--- |
795 |
} |
--- |
| 796 |
|
--- |
796 |
|
--- |
| 797 |
/// Return the call site argument number of the associated value if it is an |
--- |
797 |
/// Return the call site argument number of the associated value if it is an |
--- |
| 798 |
/// argument or call site argument, otherwise a negative value. In contrast to |
--- |
798 |
/// argument or call site argument, otherwise a negative value. In contrast to |
--- |
| 799 |
/// `getCalleArgNo` this method will always return the "operand number" from |
--- |
799 |
/// `getCalleArgNo` this method will always return the "operand number" from |
--- |
| 800 |
/// the perspective of the call site. This may not the same as the callee |
--- |
800 |
/// the perspective of the call site. This may not the same as the callee |
--- |
| 801 |
/// perspective if this is a callback call. |
--- |
801 |
/// perspective if this is a callback call. |
--- |
| 802 |
int getCallSiteArgNo() const { |
0 |
802 |
int getCallSiteArgNo() const { |
0 |
| 803 |
return getArgNo(/* CallbackCalleeArgIfApplicable */ false); |
0 |
803 |
return getArgNo(/* CallbackCalleeArgIfApplicable */ false); |
0 |
| 804 |
} |
--- |
804 |
} |
--- |
| 805 |
|
--- |
805 |
|
--- |
| 806 |
/// Return the index in the attribute list for this position. |
--- |
806 |
/// Return the index in the attribute list for this position. |
--- |
| 807 |
unsigned getAttrIdx() const { |
0 |
807 |
unsigned getAttrIdx() const { |
0 |
| 808 |
switch (getPositionKind()) { |
0 |
808 |
switch (getPositionKind()) { |
0 |
| 809 |
case IRPosition::IRP_INVALID: |
0 |
809 |
case IRPosition::IRP_INVALID: |
0 |
| 810 |
case IRPosition::IRP_FLOAT: |
--- |
810 |
case IRPosition::IRP_FLOAT: |
--- |
| 811 |
break; |
0 |
811 |
break; |
0 |
| 812 |
case IRPosition::IRP_FUNCTION: |
0 |
812 |
case IRPosition::IRP_FUNCTION: |
0 |
| 813 |
case IRPosition::IRP_CALL_SITE: |
--- |
813 |
case IRPosition::IRP_CALL_SITE: |
--- |
| 814 |
return AttributeList::FunctionIndex; |
0 |
814 |
return AttributeList::FunctionIndex; |
0 |
| 815 |
case IRPosition::IRP_RETURNED: |
0 |
815 |
case IRPosition::IRP_RETURNED: |
0 |
| 816 |
case IRPosition::IRP_CALL_SITE_RETURNED: |
--- |
816 |
case IRPosition::IRP_CALL_SITE_RETURNED: |
--- |
| 817 |
return AttributeList::ReturnIndex; |
0 |
817 |
return AttributeList::ReturnIndex; |
0 |
| 818 |
case IRPosition::IRP_ARGUMENT: |
0 |
818 |
case IRPosition::IRP_ARGUMENT: |
0 |
| 819 |
return getCalleeArgNo() + AttributeList::FirstArgIndex; |
0 |
819 |
return getCalleeArgNo() + AttributeList::FirstArgIndex; |
0 |
| 820 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
0 |
820 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
0 |
| 821 |
return getCallSiteArgNo() + AttributeList::FirstArgIndex; |
0 |
821 |
return getCallSiteArgNo() + AttributeList::FirstArgIndex; |
0 |
| 822 |
} |
--- |
822 |
} |
--- |
| 823 |
llvm_unreachable( |
0 |
823 |
llvm_unreachable( |
0 |
| 824 |
"There is no attribute index for a floating or invalid position!"); |
--- |
824 |
"There is no attribute index for a floating or invalid position!"); |
--- |
| 825 |
} |
--- |
825 |
} |
--- |
| 826 |
|
--- |
826 |
|
--- |
| 827 |
/// Return the value attributes are attached to. |
--- |
827 |
/// Return the value attributes are attached to. |
--- |
| 828 |
Value *getAttrListAnchor() const { |
0 |
828 |
Value *getAttrListAnchor() const { |
0 |
| 829 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
0 |
829 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
0 |
| 830 |
return CB; |
0 |
830 |
return CB; |
0 |
| 831 |
return getAssociatedFunction(); |
0 |
831 |
return getAssociatedFunction(); |
0 |
| 832 |
} |
--- |
832 |
} |
--- |
| 833 |
|
--- |
833 |
|
--- |
| 834 |
/// Return the attributes associated with this function or call site scope. |
--- |
834 |
/// Return the attributes associated with this function or call site scope. |
--- |
| 835 |
AttributeList getAttrList() const { |
0 |
835 |
AttributeList getAttrList() const { |
0 |
| 836 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
0 |
836 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
0 |
| 837 |
return CB->getAttributes(); |
0 |
837 |
return CB->getAttributes(); |
0 |
| 838 |
return getAssociatedFunction()->getAttributes(); |
0 |
838 |
return getAssociatedFunction()->getAttributes(); |
0 |
| 839 |
} |
--- |
839 |
} |
--- |
| 840 |
|
--- |
840 |
|
--- |
| 841 |
/// Update the attributes associated with this function or call site scope. |
--- |
841 |
/// Update the attributes associated with this function or call site scope. |
--- |
| 842 |
void setAttrList(const AttributeList &AttrList) const { |
0 |
842 |
void setAttrList(const AttributeList &AttrList) const { |
0 |
| 843 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
0 |
843 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
0 |
| 844 |
return CB->setAttributes(AttrList); |
0 |
844 |
return CB->setAttributes(AttrList); |
0 |
| 845 |
return getAssociatedFunction()->setAttributes(AttrList); |
0 |
845 |
return getAssociatedFunction()->setAttributes(AttrList); |
0 |
| 846 |
} |
--- |
846 |
} |
--- |
| 847 |
|
--- |
847 |
|
--- |
| 848 |
/// Return the number of arguments associated with this function or call site |
--- |
848 |
/// Return the number of arguments associated with this function or call site |
--- |
| 849 |
/// scope. |
--- |
849 |
/// scope. |
--- |
| 850 |
unsigned getNumArgs() const { |
--- |
850 |
unsigned getNumArgs() const { |
--- |
| 851 |
assert((getPositionKind() == IRP_CALL_SITE || |
--- |
851 |
assert((getPositionKind() == IRP_CALL_SITE || |
--- |
| 852 |
getPositionKind() == IRP_FUNCTION) && |
--- |
852 |
getPositionKind() == IRP_FUNCTION) && |
--- |
| 853 |
"Only valid for function/call site positions!"); |
--- |
853 |
"Only valid for function/call site positions!"); |
--- |
| 854 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
--- |
854 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
--- |
| 855 |
return CB->arg_size(); |
--- |
855 |
return CB->arg_size(); |
--- |
| 856 |
return getAssociatedFunction()->arg_size(); |
--- |
856 |
return getAssociatedFunction()->arg_size(); |
--- |
| 857 |
} |
--- |
857 |
} |
--- |
| 858 |
|
--- |
858 |
|
--- |
| 859 |
/// Return theargument \p ArgNo associated with this function or call site |
--- |
859 |
/// Return theargument \p ArgNo associated with this function or call site |
--- |
| 860 |
/// scope. |
--- |
860 |
/// scope. |
--- |
| 861 |
Value *getArg(unsigned ArgNo) const { |
--- |
861 |
Value *getArg(unsigned ArgNo) const { |
--- |
| 862 |
assert((getPositionKind() == IRP_CALL_SITE || |
--- |
862 |
assert((getPositionKind() == IRP_CALL_SITE || |
--- |
| 863 |
getPositionKind() == IRP_FUNCTION) && |
--- |
863 |
getPositionKind() == IRP_FUNCTION) && |
--- |
| 864 |
"Only valid for function/call site positions!"); |
--- |
864 |
"Only valid for function/call site positions!"); |
--- |
| 865 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
--- |
865 |
if (auto *CB = dyn_cast(&getAnchorValue())) |
--- |
| 866 |
return CB->getArgOperand(ArgNo); |
--- |
866 |
return CB->getArgOperand(ArgNo); |
--- |
| 867 |
return getAssociatedFunction()->getArg(ArgNo); |
--- |
867 |
return getAssociatedFunction()->getArg(ArgNo); |
--- |
| 868 |
} |
--- |
868 |
} |
--- |
| 869 |
|
--- |
869 |
|
--- |
| 870 |
/// Return the associated position kind. |
--- |
870 |
/// Return the associated position kind. |
--- |
| 871 |
Kind getPositionKind() const { |
0 |
871 |
Kind getPositionKind() const { |
0 |
| 872 |
char EncodingBits = getEncodingBits(); |
0 |
872 |
char EncodingBits = getEncodingBits(); |
0 |
| 873 |
if (EncodingBits == ENC_CALL_SITE_ARGUMENT_USE) |
0 |
873 |
if (EncodingBits == ENC_CALL_SITE_ARGUMENT_USE) |
0 |
| 874 |
return IRP_CALL_SITE_ARGUMENT; |
0 |
874 |
return IRP_CALL_SITE_ARGUMENT; |
0 |
| 875 |
if (EncodingBits == ENC_FLOATING_FUNCTION) |
0 |
875 |
if (EncodingBits == ENC_FLOATING_FUNCTION) |
0 |
| 876 |
return IRP_FLOAT; |
0 |
876 |
return IRP_FLOAT; |
0 |
| 877 |
|
--- |
877 |
|
--- |
| 878 |
Value *V = getAsValuePtr(); |
0 |
878 |
Value *V = getAsValuePtr(); |
0 |
| 879 |
if (!V) |
0 |
879 |
if (!V) |
0 |
| 880 |
return IRP_INVALID; |
0 |
880 |
return IRP_INVALID; |
0 |
| 881 |
if (isa(V)) |
0 |
881 |
if (isa(V)) |
0 |
| 882 |
return IRP_ARGUMENT; |
0 |
882 |
return IRP_ARGUMENT; |
0 |
| 883 |
if (isa(V)) |
0 |
883 |
if (isa(V)) |
0 |
| 884 |
return isReturnPosition(EncodingBits) ? IRP_RETURNED : IRP_FUNCTION; |
0 |
884 |
return isReturnPosition(EncodingBits) ? IRP_RETURNED : IRP_FUNCTION; |
0 |
| 885 |
if (isa(V)) |
0 |
885 |
if (isa(V)) |
0 |
| 886 |
return isReturnPosition(EncodingBits) ? IRP_CALL_SITE_RETURNED |
0 |
886 |
return isReturnPosition(EncodingBits) ? IRP_CALL_SITE_RETURNED |
0 |
| 887 |
: IRP_CALL_SITE; |
0 |
887 |
: IRP_CALL_SITE; |
0 |
| 888 |
return IRP_FLOAT; |
0 |
888 |
return IRP_FLOAT; |
0 |
| 889 |
} |
--- |
889 |
} |
--- |
| 890 |
|
--- |
890 |
|
--- |
| 891 |
bool isAnyCallSitePosition() const { |
0 |
891 |
bool isAnyCallSitePosition() const { |
0 |
| 892 |
switch (getPositionKind()) { |
0 |
892 |
switch (getPositionKind()) { |
0 |
| 893 |
case IRPosition::IRP_CALL_SITE: |
0 |
893 |
case IRPosition::IRP_CALL_SITE: |
0 |
| 894 |
case IRPosition::IRP_CALL_SITE_RETURNED: |
--- |
894 |
case IRPosition::IRP_CALL_SITE_RETURNED: |
--- |
| 895 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
--- |
895 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
--- |
| 896 |
return true; |
0 |
896 |
return true; |
0 |
| 897 |
default: |
0 |
897 |
default: |
0 |
| 898 |
return false; |
0 |
898 |
return false; |
0 |
| 899 |
} |
--- |
899 |
} |
--- |
| 900 |
} |
--- |
900 |
} |
--- |
| 901 |
|
--- |
901 |
|
--- |
| 902 |
/// Return true if the position is an argument or call site argument. |
--- |
902 |
/// Return true if the position is an argument or call site argument. |
--- |
| 903 |
bool isArgumentPosition() const { |
--- |
903 |
bool isArgumentPosition() const { |
--- |
| 904 |
switch (getPositionKind()) { |
--- |
904 |
switch (getPositionKind()) { |
--- |
| 905 |
case IRPosition::IRP_ARGUMENT: |
--- |
905 |
case IRPosition::IRP_ARGUMENT: |
--- |
| 906 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
--- |
906 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
--- |
| 907 |
return true; |
--- |
907 |
return true; |
--- |
| 908 |
default: |
--- |
908 |
default: |
--- |
| 909 |
return false; |
--- |
909 |
return false; |
--- |
| 910 |
} |
--- |
910 |
} |
--- |
| 911 |
} |
--- |
911 |
} |
--- |
| 912 |
|
--- |
912 |
|
--- |
| 913 |
/// Return the same position without the call base context. |
--- |
913 |
/// Return the same position without the call base context. |
--- |
| 914 |
IRPosition stripCallBaseContext() const { |
0 |
914 |
IRPosition stripCallBaseContext() const { |
0 |
| 915 |
IRPosition Result = *this; |
0 |
915 |
IRPosition Result = *this; |
0 |
| 916 |
Result.CBContext = nullptr; |
0 |
916 |
Result.CBContext = nullptr; |
0 |
| 917 |
return Result; |
0 |
917 |
return Result; |
0 |
| 918 |
} |
--- |
918 |
} |
--- |
| 919 |
|
--- |
919 |
|
--- |
| 920 |
/// Get the call base context from the position. |
--- |
920 |
/// Get the call base context from the position. |
--- |
| 921 |
const CallBaseContext *getCallBaseContext() const { return CBContext; } |
0 |
921 |
const CallBaseContext *getCallBaseContext() const { return CBContext; } |
0 |
| 922 |
|
--- |
922 |
|
--- |
| 923 |
/// Check if the position has any call base context. |
--- |
923 |
/// Check if the position has any call base context. |
--- |
| 924 |
bool hasCallBaseContext() const { return CBContext != nullptr; } |
0 |
924 |
bool hasCallBaseContext() const { return CBContext != nullptr; } |
0 |
| 925 |
|
--- |
925 |
|
--- |
| 926 |
/// Special DenseMap key values. |
--- |
926 |
/// Special DenseMap key values. |
--- |
| 927 |
/// |
--- |
927 |
/// |
--- |
| 928 |
///{ |
--- |
928 |
///{ |
--- |
| 929 |
static const IRPosition EmptyKey; |
--- |
929 |
static const IRPosition EmptyKey; |
--- |
| 930 |
static const IRPosition TombstoneKey; |
--- |
930 |
static const IRPosition TombstoneKey; |
--- |
| 931 |
///} |
--- |
931 |
///} |
--- |
| 932 |
|
--- |
932 |
|
--- |
| 933 |
/// Conversion into a void * to allow reuse of pointer hashing. |
--- |
933 |
/// Conversion into a void * to allow reuse of pointer hashing. |
--- |
| 934 |
operator void *() const { return Enc.getOpaqueValue(); } |
0 |
934 |
operator void *() const { return Enc.getOpaqueValue(); } |
0 |
| 935 |
|
--- |
935 |
|
--- |
| 936 |
private: |
--- |
936 |
private: |
--- |
| 937 |
/// Private constructor for special values only! |
--- |
937 |
/// Private constructor for special values only! |
--- |
| 938 |
explicit IRPosition(void *Ptr, const CallBaseContext *CBContext = nullptr) |
2 |
938 |
explicit IRPosition(void *Ptr, const CallBaseContext *CBContext = nullptr) |
2 |
| 939 |
: CBContext(CBContext) { |
2 |
939 |
: CBContext(CBContext) { |
2 |
| 940 |
Enc.setFromOpaqueValue(Ptr); |
2 |
940 |
Enc.setFromOpaqueValue(Ptr); |
2 |
| 941 |
} |
2 |
941 |
} |
2 |
| 942 |
|
--- |
942 |
|
--- |
| 943 |
/// IRPosition anchored at \p AnchorVal with kind/argument numbet \p PK. |
--- |
943 |
/// IRPosition anchored at \p AnchorVal with kind/argument numbet \p PK. |
--- |
| 944 |
explicit IRPosition(Value &AnchorVal, Kind PK, |
0 |
944 |
explicit IRPosition(Value &AnchorVal, Kind PK, |
0 |
| 945 |
const CallBaseContext *CBContext = nullptr) |
--- |
945 |
const CallBaseContext *CBContext = nullptr) |
--- |
| 946 |
: CBContext(CBContext) { |
0 |
946 |
: CBContext(CBContext) { |
0 |
| 947 |
switch (PK) { |
0 |
947 |
switch (PK) { |
0 |
| 948 |
case IRPosition::IRP_INVALID: |
0 |
948 |
case IRPosition::IRP_INVALID: |
0 |
| 949 |
llvm_unreachable("Cannot create invalid IRP with an anchor value!"); |
0 |
949 |
llvm_unreachable("Cannot create invalid IRP with an anchor value!"); |
0 |
| 950 |
break; |
--- |
950 |
break; |
--- |
| 951 |
case IRPosition::IRP_FLOAT: |
0 |
951 |
case IRPosition::IRP_FLOAT: |
0 |
| 952 |
// Special case for floating functions. |
--- |
952 |
// Special case for floating functions. |
--- |
| 953 |
if (isa(AnchorVal) || isa(AnchorVal)) |
0 |
953 |
if (isa(AnchorVal) || isa(AnchorVal)) |
0 |
| 954 |
Enc = {&AnchorVal, ENC_FLOATING_FUNCTION}; |
0 |
954 |
Enc = {&AnchorVal, ENC_FLOATING_FUNCTION}; |
0 |
| 955 |
else |
--- |
955 |
else |
--- |
| 956 |
Enc = {&AnchorVal, ENC_VALUE}; |
0 |
956 |
Enc = {&AnchorVal, ENC_VALUE}; |
0 |
| 957 |
break; |
0 |
957 |
break; |
0 |
| 958 |
case IRPosition::IRP_FUNCTION: |
0 |
958 |
case IRPosition::IRP_FUNCTION: |
0 |
| 959 |
case IRPosition::IRP_CALL_SITE: |
--- |
959 |
case IRPosition::IRP_CALL_SITE: |
--- |
| 960 |
Enc = {&AnchorVal, ENC_VALUE}; |
0 |
960 |
Enc = {&AnchorVal, ENC_VALUE}; |
0 |
| 961 |
break; |
0 |
961 |
break; |
0 |
| 962 |
case IRPosition::IRP_RETURNED: |
0 |
962 |
case IRPosition::IRP_RETURNED: |
0 |
| 963 |
case IRPosition::IRP_CALL_SITE_RETURNED: |
--- |
963 |
case IRPosition::IRP_CALL_SITE_RETURNED: |
--- |
| 964 |
Enc = {&AnchorVal, ENC_RETURNED_VALUE}; |
0 |
964 |
Enc = {&AnchorVal, ENC_RETURNED_VALUE}; |
0 |
| 965 |
break; |
0 |
965 |
break; |
0 |
| 966 |
case IRPosition::IRP_ARGUMENT: |
0 |
966 |
case IRPosition::IRP_ARGUMENT: |
0 |
| 967 |
Enc = {&AnchorVal, ENC_VALUE}; |
0 |
967 |
Enc = {&AnchorVal, ENC_VALUE}; |
0 |
| 968 |
break; |
0 |
968 |
break; |
0 |
| 969 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
0 |
969 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: |
0 |
| 970 |
llvm_unreachable( |
0 |
970 |
llvm_unreachable( |
0 |
| 971 |
"Cannot create call site argument IRP with an anchor value!"); |
--- |
971 |
"Cannot create call site argument IRP with an anchor value!"); |
--- |
| 972 |
break; |
--- |
972 |
break; |
--- |
| 973 |
} |
--- |
973 |
} |
--- |
| 974 |
verify(); |
0 |
974 |
verify(); |
0 |
| 975 |
} |
0 |
975 |
} |
0 |
| 976 |
|
--- |
976 |
|
--- |
| 977 |
/// Return the callee argument number of the associated value if it is an |
--- |
977 |
/// Return the callee argument number of the associated value if it is an |
--- |
| 978 |
/// argument or call site argument. See also `getCalleeArgNo` and |
--- |
978 |
/// argument or call site argument. See also `getCalleeArgNo` and |
--- |
| 979 |
/// `getCallSiteArgNo`. |
--- |
979 |
/// `getCallSiteArgNo`. |
--- |
| 980 |
int getArgNo(bool CallbackCalleeArgIfApplicable) const { |
0 |
980 |
int getArgNo(bool CallbackCalleeArgIfApplicable) const { |
0 |
| 981 |
if (CallbackCalleeArgIfApplicable) |
0 |
981 |
if (CallbackCalleeArgIfApplicable) |
0 |
| 982 |
if (Argument *Arg = getAssociatedArgument()) |
0 |
982 |
if (Argument *Arg = getAssociatedArgument()) |
0 |
| 983 |
return Arg->getArgNo(); |
0 |
983 |
return Arg->getArgNo(); |
0 |
| 984 |
switch (getPositionKind()) { |
0 |
984 |
switch (getPositionKind()) { |
0 |
| 985 |
case IRPosition::IRP_ARGUMENT: |
0 |
985 |
case IRPosition::IRP_ARGUMENT: |
0 |
| 986 |
return cast(getAsValuePtr())->getArgNo(); |
0 |
986 |
return cast(getAsValuePtr())->getArgNo(); |
0 |
| 987 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: { |
0 |
987 |
case IRPosition::IRP_CALL_SITE_ARGUMENT: { |
0 |
| 988 |
Use &U = *getAsUsePtr(); |
0 |
988 |
Use &U = *getAsUsePtr(); |
0 |
| 989 |
return cast(U.getUser())->getArgOperandNo(&U); |
0 |
989 |
return cast(U.getUser())->getArgOperandNo(&U); |
0 |
| 990 |
} |
--- |
990 |
} |
--- |
| 991 |
default: |
0 |
991 |
default: |
0 |
| 992 |
return -1; |
0 |
992 |
return -1; |
0 |
| 993 |
} |
--- |
993 |
} |
--- |
| 994 |
} |
--- |
994 |
} |
--- |
| 995 |
|
--- |
995 |
|
--- |
| 996 |
/// IRPosition for the use \p U. The position kind \p PK needs to be |
--- |
996 |
/// IRPosition for the use \p U. The position kind \p PK needs to be |
--- |
| 997 |
/// IRP_CALL_SITE_ARGUMENT, the anchor value is the user, the associated value |
--- |
997 |
/// IRP_CALL_SITE_ARGUMENT, the anchor value is the user, the associated value |
--- |
| 998 |
/// the used value. |
--- |
998 |
/// the used value. |
--- |
| 999 |
explicit IRPosition(Use &U, Kind PK) { |
0 |
999 |
explicit IRPosition(Use &U, Kind PK) { |
0 |
| 1000 |
assert(PK == IRP_CALL_SITE_ARGUMENT && |
0 |
1000 |
assert(PK == IRP_CALL_SITE_ARGUMENT && |
0 |
| 1001 |
"Use constructor is for call site arguments only!"); |
--- |
1001 |
"Use constructor is for call site arguments only!"); |
--- |
| 1002 |
Enc = {&U, ENC_CALL_SITE_ARGUMENT_USE}; |
0 |
1002 |
Enc = {&U, ENC_CALL_SITE_ARGUMENT_USE}; |
0 |
| 1003 |
verify(); |
0 |
1003 |
verify(); |
0 |
| 1004 |
} |
0 |
1004 |
} |
0 |
| 1005 |
|
--- |
1005 |
|
--- |
| 1006 |
/// Verify internal invariants. |
--- |
1006 |
/// Verify internal invariants. |
--- |
| 1007 |
void verify(); |
--- |
1007 |
void verify(); |
--- |
| 1008 |
|
--- |
1008 |
|
--- |
| 1009 |
/// Return the underlying pointer as Value *, valid for all positions but |
--- |
1009 |
/// Return the underlying pointer as Value *, valid for all positions but |
--- |
| 1010 |
/// IRP_CALL_SITE_ARGUMENT. |
--- |
1010 |
/// IRP_CALL_SITE_ARGUMENT. |
--- |
| 1011 |
Value *getAsValuePtr() const { |
0 |
1011 |
Value *getAsValuePtr() const { |
0 |
| 1012 |
assert(getEncodingBits() != ENC_CALL_SITE_ARGUMENT_USE && |
0 |
1012 |
assert(getEncodingBits() != ENC_CALL_SITE_ARGUMENT_USE && |
0 |
| 1013 |
"Not a value pointer!"); |
--- |
1013 |
"Not a value pointer!"); |
--- |
| 1014 |
return reinterpret_cast(Enc.getPointer()); |
0 |
1014 |
return reinterpret_cast(Enc.getPointer()); |
0 |
| 1015 |
} |
--- |
1015 |
} |
--- |
| 1016 |
|
--- |
1016 |
|
--- |
| 1017 |
/// Return the underlying pointer as Use *, valid only for |
--- |
1017 |
/// Return the underlying pointer as Use *, valid only for |
--- |
| 1018 |
/// IRP_CALL_SITE_ARGUMENT positions. |
--- |
1018 |
/// IRP_CALL_SITE_ARGUMENT positions. |
--- |
| 1019 |
Use *getAsUsePtr() const { |
0 |
1019 |
Use *getAsUsePtr() const { |
0 |
| 1020 |
assert(getEncodingBits() == ENC_CALL_SITE_ARGUMENT_USE && |
0 |
1020 |
assert(getEncodingBits() == ENC_CALL_SITE_ARGUMENT_USE && |
0 |
| 1021 |
"Not a value pointer!"); |
--- |
1021 |
"Not a value pointer!"); |
--- |
| 1022 |
return reinterpret_cast |
0 |
1022 |
return reinterpret_cast |
0 |
| 1023 |
} |
--- |
1023 |
} |
--- |
| 1024 |
|
--- |
1024 |
|
--- |
| 1025 |
/// Return true if \p EncodingBits describe a returned or call site returned |
--- |
1025 |
/// Return true if \p EncodingBits describe a returned or call site returned |
--- |
| 1026 |
/// position. |
--- |
1026 |
/// position. |
--- |
| 1027 |
static bool isReturnPosition(char EncodingBits) { |
0 |
1027 |
static bool isReturnPosition(char EncodingBits) { |
0 |
| 1028 |
return EncodingBits == ENC_RETURNED_VALUE; |
0 |
1028 |
return EncodingBits == ENC_RETURNED_VALUE; |
0 |
| 1029 |
} |
--- |
1029 |
} |
--- |
| 1030 |
|
--- |
1030 |
|
--- |
| 1031 |
/// Return true if the encoding bits describe a returned or call site returned |
--- |
1031 |
/// Return true if the encoding bits describe a returned or call site returned |
--- |
| 1032 |
/// position. |
--- |
1032 |
/// position. |
--- |
| 1033 |
bool isReturnPosition() const { return isReturnPosition(getEncodingBits()); } |
--- |
1033 |
bool isReturnPosition() const { return isReturnPosition(getEncodingBits()); } |
--- |
| 1034 |
|
--- |
1034 |
|
--- |
| 1035 |
/// The encoding of the IRPosition is a combination of a pointer and two |
--- |
1035 |
/// The encoding of the IRPosition is a combination of a pointer and two |
--- |
| 1036 |
/// encoding bits. The values of the encoding bits are defined in the enum |
--- |
1036 |
/// encoding bits. The values of the encoding bits are defined in the enum |
--- |
| 1037 |
/// below. The pointer is either a Value* (for the first three encoding bit |
--- |
1037 |
/// below. The pointer is either a Value* (for the first three encoding bit |
--- |
| 1038 |
/// combinations) or Use* (for ENC_CALL_SITE_ARGUMENT_USE). |
--- |
1038 |
/// combinations) or Use* (for ENC_CALL_SITE_ARGUMENT_USE). |
--- |
| 1039 |
/// |
--- |
1039 |
/// |
--- |
| 1040 |
///{ |
--- |
1040 |
///{ |
--- |
| 1041 |
enum { |
--- |
1041 |
enum { |
--- |
| 1042 |
ENC_VALUE = 0b00, |
--- |
1042 |
ENC_VALUE = 0b00, |
--- |
| 1043 |
ENC_RETURNED_VALUE = 0b01, |
--- |
1043 |
ENC_RETURNED_VALUE = 0b01, |
--- |
| 1044 |
ENC_FLOATING_FUNCTION = 0b10, |
--- |
1044 |
ENC_FLOATING_FUNCTION = 0b10, |
--- |
| 1045 |
ENC_CALL_SITE_ARGUMENT_USE = 0b11, |
--- |
1045 |
ENC_CALL_SITE_ARGUMENT_USE = 0b11, |
--- |
| 1046 |
}; |
--- |
1046 |
}; |
--- |
| 1047 |
|
--- |
1047 |
|
--- |
| 1048 |
// Reserve the maximal amount of bits so there is no need to mask out the |
--- |
1048 |
// Reserve the maximal amount of bits so there is no need to mask out the |
--- |
| 1049 |
// remaining ones. We will not encode anything else in the pointer anyway. |
--- |
1049 |
// remaining ones. We will not encode anything else in the pointer anyway. |
--- |
| 1050 |
static constexpr int NumEncodingBits = |
--- |
1050 |
static constexpr int NumEncodingBits = |
--- |
| 1051 |
PointerLikeTypeTraits::NumLowBitsAvailable; |
--- |
1051 |
PointerLikeTypeTraits::NumLowBitsAvailable; |
--- |
| 1052 |
static_assert(NumEncodingBits >= 2, "At least two bits are required!"); |
--- |
1052 |
static_assert(NumEncodingBits >= 2, "At least two bits are required!"); |
--- |
| 1053 |
|
--- |
1053 |
|
--- |
| 1054 |
/// The pointer with the encoding bits. |
--- |
1054 |
/// The pointer with the encoding bits. |
--- |
| 1055 |
PointerIntPair Enc; |
--- |
1055 |
PointerIntPair Enc; |
--- |
| 1056 |
///} |
--- |
1056 |
///} |
--- |
| 1057 |
|
--- |
1057 |
|
--- |
| 1058 |
/// Call base context. Used for callsite specific analysis. |
--- |
1058 |
/// Call base context. Used for callsite specific analysis. |
--- |
| 1059 |
const CallBaseContext *CBContext = nullptr; |
--- |
1059 |
const CallBaseContext *CBContext = nullptr; |
--- |
| 1060 |
|
--- |
1060 |
|
--- |
| 1061 |
/// Return the encoding bits. |
--- |
1061 |
/// Return the encoding bits. |
--- |
| 1062 |
char getEncodingBits() const { return Enc.getInt(); } |
0 |
1062 |
char getEncodingBits() const { return Enc.getInt(); } |
0 |
| 1063 |
}; |
--- |
1063 |
}; |
--- |
| 1064 |
|
--- |
1064 |
|
--- |
| 1065 |
/// Helper that allows IRPosition as a key in a DenseMap. |
--- |
1065 |
/// Helper that allows IRPosition as a key in a DenseMap. |
--- |
| 1066 |
template <> struct DenseMapInfo { |
--- |
1066 |
template <> struct DenseMapInfo { |
--- |
| 1067 |
static inline IRPosition getEmptyKey() { return IRPosition::EmptyKey; } |
0 |
1067 |
static inline IRPosition getEmptyKey() { return IRPosition::EmptyKey; } |
0 |
| 1068 |
static inline IRPosition getTombstoneKey() { |
0 |
1068 |
static inline IRPosition getTombstoneKey() { |
0 |
| 1069 |
return IRPosition::TombstoneKey; |
0 |
1069 |
return IRPosition::TombstoneKey; |
0 |
| 1070 |
} |
--- |
1070 |
} |
--- |
| 1071 |
static unsigned getHashValue(const IRPosition &IRP) { |
0 |
1071 |
static unsigned getHashValue(const IRPosition &IRP) { |
0 |
| 1072 |
return (DenseMapInfo::getHashValue(IRP) << 4) ^ |
0 |
1072 |
return (DenseMapInfo::getHashValue(IRP) << 4) ^ |
0 |
| 1073 |
(DenseMapInfo::getHashValue(IRP.getCallBaseContext())); |
0 |
1073 |
(DenseMapInfo::getHashValue(IRP.getCallBaseContext())); |
0 |
| 1074 |
} |
--- |
1074 |
} |
--- |
| 1075 |
|
--- |
1075 |
|
--- |
| 1076 |
static bool isEqual(const IRPosition &a, const IRPosition &b) { |
0 |
1076 |
static bool isEqual(const IRPosition &a, const IRPosition &b) { |
0 |
| 1077 |
return a == b; |
0 |
1077 |
return a == b; |
0 |
| 1078 |
} |
--- |
1078 |
} |
--- |
| 1079 |
}; |
--- |
1079 |
}; |
--- |
| 1080 |
|
--- |
1080 |
|
--- |
| 1081 |
/// A visitor class for IR positions. |
--- |
1081 |
/// A visitor class for IR positions. |
--- |
| 1082 |
/// |
--- |
1082 |
/// |
--- |
| 1083 |
/// Given a position P, the SubsumingPositionIterator allows to visit "subsuming |
--- |
1083 |
/// Given a position P, the SubsumingPositionIterator allows to visit "subsuming |
--- |
| 1084 |
/// positions" wrt. attributes/information. Thus, if a piece of information |
--- |
1084 |
/// positions" wrt. attributes/information. Thus, if a piece of information |
--- |
| 1085 |
/// holds for a subsuming position, it also holds for the position P. |
--- |
1085 |
/// holds for a subsuming position, it also holds for the position P. |
--- |
| 1086 |
/// |
--- |
1086 |
/// |
--- |
| 1087 |
/// The subsuming positions always include the initial position and then, |
--- |
1087 |
/// The subsuming positions always include the initial position and then, |
--- |
| 1088 |
/// depending on the position kind, additionally the following ones: |
--- |
1088 |
/// depending on the position kind, additionally the following ones: |
--- |
| 1089 |
/// - for IRP_RETURNED: |
--- |
1089 |
/// - for IRP_RETURNED: |
--- |
| 1090 |
/// - the function (IRP_FUNCTION) |
--- |
1090 |
/// - the function (IRP_FUNCTION) |
--- |
| 1091 |
/// - for IRP_ARGUMENT: |
--- |
1091 |
/// - for IRP_ARGUMENT: |
--- |
| 1092 |
/// - the function (IRP_FUNCTION) |
--- |
1092 |
/// - the function (IRP_FUNCTION) |
--- |
| 1093 |
/// - for IRP_CALL_SITE: |
--- |
1093 |
/// - for IRP_CALL_SITE: |
--- |
| 1094 |
/// - the callee (IRP_FUNCTION), if known |
--- |
1094 |
/// - the callee (IRP_FUNCTION), if known |
--- |
| 1095 |
/// - for IRP_CALL_SITE_RETURNED: |
--- |
1095 |
/// - for IRP_CALL_SITE_RETURNED: |
--- |
| 1096 |
/// - the callee (IRP_RETURNED), if known |
--- |
1096 |
/// - the callee (IRP_RETURNED), if known |
--- |
| 1097 |
/// - the call site (IRP_FUNCTION) |
--- |
1097 |
/// - the call site (IRP_FUNCTION) |
--- |
| 1098 |
/// - the callee (IRP_FUNCTION), if known |
--- |
1098 |
/// - the callee (IRP_FUNCTION), if known |
--- |
| 1099 |
/// - for IRP_CALL_SITE_ARGUMENT: |
--- |
1099 |
/// - for IRP_CALL_SITE_ARGUMENT: |
--- |
| 1100 |
/// - the argument of the callee (IRP_ARGUMENT), if known |
--- |
1100 |
/// - the argument of the callee (IRP_ARGUMENT), if known |
--- |
| 1101 |
/// - the callee (IRP_FUNCTION), if known |
--- |
1101 |
/// - the callee (IRP_FUNCTION), if known |
--- |
| 1102 |
/// - the position the call site argument is associated with if it is not |
--- |
1102 |
/// - the position the call site argument is associated with if it is not |
--- |
| 1103 |
/// anchored to the call site, e.g., if it is an argument then the argument |
--- |
1103 |
/// anchored to the call site, e.g., if it is an argument then the argument |
--- |
| 1104 |
/// (IRP_ARGUMENT) |
--- |
1104 |
/// (IRP_ARGUMENT) |
--- |
| 1105 |
class SubsumingPositionIterator { |
--- |
1105 |
class SubsumingPositionIterator { |
--- |
| 1106 |
SmallVector IRPositions; |
--- |
1106 |
SmallVector IRPositions; |
--- |
| 1107 |
using iterator = decltype(IRPositions)::iterator; |
--- |
1107 |
using iterator = decltype(IRPositions)::iterator; |
--- |
| 1108 |
|
--- |
1108 |
|
--- |
| 1109 |
public: |
--- |
1109 |
public: |
--- |
| 1110 |
SubsumingPositionIterator(const IRPosition &IRP); |
--- |
1110 |
SubsumingPositionIterator(const IRPosition &IRP); |
--- |
| 1111 |
iterator begin() { return IRPositions.begin(); } |
0 |
1111 |
iterator begin() { return IRPositions.begin(); } |
0 |
| 1112 |
iterator end() { return IRPositions.end(); } |
0 |
1112 |
iterator end() { return IRPositions.end(); } |
0 |
| 1113 |
}; |
--- |
1113 |
}; |
--- |
| 1114 |
|
--- |
1114 |
|
--- |
| 1115 |
/// Wrapper for FunctionAnalysisManager. |
--- |
1115 |
/// Wrapper for FunctionAnalysisManager. |
--- |
| 1116 |
struct AnalysisGetter { |
--- |
1116 |
struct AnalysisGetter { |
--- |
| 1117 |
// The client may be running the old pass manager, in which case, we need to |
--- |
1117 |
// The client may be running the old pass manager, in which case, we need to |
--- |
| 1118 |
// map the requested Analysis to its equivalent wrapper in the old pass |
--- |
1118 |
// map the requested Analysis to its equivalent wrapper in the old pass |
--- |
| 1119 |
// manager. The scheme implemented here does not require every Analysis to be |
--- |
1119 |
// manager. The scheme implemented here does not require every Analysis to be |
--- |
| 1120 |
// updated. Only those new analyses that the client cares about in the old |
--- |
1120 |
// updated. Only those new analyses that the client cares about in the old |
--- |
| 1121 |
// pass manager need to expose a LegacyWrapper type, and that wrapper should |
--- |
1121 |
// pass manager need to expose a LegacyWrapper type, and that wrapper should |
--- |
| 1122 |
// support a getResult() method that matches the new Analysis. |
--- |
1122 |
// support a getResult() method that matches the new Analysis. |
--- |
| 1123 |
// |
--- |
1123 |
// |
--- |
| 1124 |
// We need SFINAE to check for the LegacyWrapper, but function templates don't |
--- |
1124 |
// We need SFINAE to check for the LegacyWrapper, but function templates don't |
--- |
| 1125 |
// allow partial specialization, which is needed in this case. So instead, we |
--- |
1125 |
// allow partial specialization, which is needed in this case. So instead, we |
--- |
| 1126 |
// use a constexpr bool to perform the SFINAE, and then use this information |
--- |
1126 |
// use a constexpr bool to perform the SFINAE, and then use this information |
--- |
| 1127 |
// inside the function template. |
--- |
1127 |
// inside the function template. |
--- |
| 1128 |
template |
--- |
1128 |
template |
--- |
| 1129 |
static constexpr bool HasLegacyWrapper = false; |
--- |
1129 |
static constexpr bool HasLegacyWrapper = false; |
--- |
| 1130 |
|
--- |
1130 |
|
--- |
| 1131 |
template |
--- |
1131 |
template |
--- |
| 1132 |
typename Analysis::Result *getAnalysis(const Function &F, |
0 |
1132 |
typename Analysis::Result *getAnalysis(const Function &F, |
0 |
| 1133 |
bool RequestCachedOnly = false) { |
--- |
1133 |
bool RequestCachedOnly = false) { |
--- |
| 1134 |
if (!LegacyPass && !FAM) |
0 |
1134 |
if (!LegacyPass && !FAM) |
0 |
| 1135 |
return nullptr; |
0 |
1135 |
return nullptr; |
0 |
| 1136 |
if (FAM) { |
0 |
1136 |
if (FAM) { |
0 |
| 1137 |
if (CachedOnly || RequestCachedOnly) |
0 |
1137 |
if (CachedOnly || RequestCachedOnly) |
0 |
| 1138 |
return FAM->getCachedResult(const_cast(F)); |
0 |
1138 |
return FAM->getCachedResult(const_cast(F)); |
0 |
| 1139 |
return &FAM->getResult(const_cast(F)); |
0 |
1139 |
return &FAM->getResult(const_cast(F)); |
0 |
| 1140 |
} |
--- |
1140 |
} |
--- |
| 1141 |
if constexpr (HasLegacyWrapper) { |
--- |
1141 |
if constexpr (HasLegacyWrapper) { |
--- |
| 1142 |
if (!CachedOnly && !RequestCachedOnly) |
--- |
1142 |
if (!CachedOnly && !RequestCachedOnly) |
--- |
| 1143 |
return &LegacyPass |
--- |
1143 |
return &LegacyPass |
--- |
| 1144 |
->getAnalysis( |
--- |
1144 |
->getAnalysis( |
--- |
| 1145 |
const_cast(F)) |
--- |
1145 |
const_cast(F)) |
--- |
| 1146 |
.getResult(); |
--- |
1146 |
.getResult(); |
--- |
| 1147 |
if (auto *P = |
--- |
1147 |
if (auto *P = |
--- |
| 1148 |
LegacyPass |
--- |
1148 |
LegacyPass |
--- |
| 1149 |
->getAnalysisIfAvailable()) |
--- |
1149 |
->getAnalysisIfAvailable()) |
--- |
| 1150 |
return &P->getResult(); |
--- |
1150 |
return &P->getResult(); |
--- |
| 1151 |
} |
--- |
1151 |
} |
--- |
| 1152 |
return nullptr; |
0 |
1152 |
return nullptr; |
0 |
| 1153 |
} |
--- |
1153 |
} |
--- |
| 1154 |
|
--- |
1154 |
|
--- |
| 1155 |
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false) |
0 |
1155 |
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false) |
0 |
| 1156 |
: FAM(&FAM), CachedOnly(CachedOnly) {} |
0 |
1156 |
: FAM(&FAM), CachedOnly(CachedOnly) {} |
0 |
| 1157 |
AnalysisGetter(Pass *P, bool CachedOnly = false) |
--- |
1157 |
AnalysisGetter(Pass *P, bool CachedOnly = false) |
--- |
| 1158 |
: LegacyPass(P), CachedOnly(CachedOnly) {} |
--- |
1158 |
: LegacyPass(P), CachedOnly(CachedOnly) {} |
--- |
| 1159 |
AnalysisGetter() = default; |
--- |
1159 |
AnalysisGetter() = default; |
--- |
| 1160 |
|
--- |
1160 |
|
--- |
| 1161 |
private: |
--- |
1161 |
private: |
--- |
| 1162 |
FunctionAnalysisManager *FAM = nullptr; |
--- |
1162 |
FunctionAnalysisManager *FAM = nullptr; |
--- |
| 1163 |
Pass *LegacyPass = nullptr; |
--- |
1163 |
Pass *LegacyPass = nullptr; |
--- |
| 1164 |
|
--- |
1164 |
|
--- |
| 1165 |
/// If \p CachedOnly is true, no pass is created, just existing results are |
--- |
1165 |
/// If \p CachedOnly is true, no pass is created, just existing results are |
--- |
| 1166 |
/// used. Also available per request. |
--- |
1166 |
/// used. Also available per request. |
--- |
| 1167 |
bool CachedOnly = false; |
--- |
1167 |
bool CachedOnly = false; |
--- |
| 1168 |
}; |
--- |
1168 |
}; |
--- |
| 1169 |
|
--- |
1169 |
|
--- |
| 1170 |
template |
--- |
1170 |
template |
--- |
| 1171 |
constexpr bool AnalysisGetter::HasLegacyWrapper< |
--- |
1171 |
constexpr bool AnalysisGetter::HasLegacyWrapper< |
--- |
| 1172 |
Analysis, std::void_t> = true; |
--- |
1172 |
Analysis, std::void_t> = true; |
--- |
| 1173 |
|
--- |
1173 |
|
--- |
| 1174 |
/// Data structure to hold cached (LLVM-IR) information. |
--- |
1174 |
/// Data structure to hold cached (LLVM-IR) information. |
--- |
| 1175 |
/// |
--- |
1175 |
/// |
--- |
| 1176 |
/// All attributes are given an InformationCache object at creation time to |
--- |
1176 |
/// All attributes are given an InformationCache object at creation time to |
--- |
| 1177 |
/// avoid inspection of the IR by all of them individually. This default |
--- |
1177 |
/// avoid inspection of the IR by all of them individually. This default |
--- |
| 1178 |
/// InformationCache will hold information required by 'default' attributes, |
--- |
1178 |
/// InformationCache will hold information required by 'default' attributes, |
--- |
| 1179 |
/// thus the ones deduced when Attributor::identifyDefaultAbstractAttributes(..) |
--- |
1179 |
/// thus the ones deduced when Attributor::identifyDefaultAbstractAttributes(..) |
--- |
| 1180 |
/// is called. |
--- |
1180 |
/// is called. |
--- |
| 1181 |
/// |
--- |
1181 |
/// |
--- |
| 1182 |
/// If custom abstract attributes, registered manually through |
--- |
1182 |
/// If custom abstract attributes, registered manually through |
--- |
| 1183 |
/// Attributor::registerAA(...), need more information, especially if it is not |
--- |
1183 |
/// Attributor::registerAA(...), need more information, especially if it is not |
--- |
| 1184 |
/// reusable, it is advised to inherit from the InformationCache and cast the |
--- |
1184 |
/// reusable, it is advised to inherit from the InformationCache and cast the |
--- |
| 1185 |
/// instance down in the abstract attributes. |
--- |
1185 |
/// instance down in the abstract attributes. |
--- |
| 1186 |
struct InformationCache { |
--- |
1186 |
struct InformationCache { |
--- |
| 1187 |
InformationCache(const Module &M, AnalysisGetter &AG, |
0 |
1187 |
InformationCache(const Module &M, AnalysisGetter &AG, |
0 |
| 1188 |
BumpPtrAllocator &Allocator, SetVector *CGSCC, |
--- |
1188 |
BumpPtrAllocator &Allocator, SetVector *CGSCC, |
--- |
| 1189 |
bool UseExplorer = true) |
--- |
1189 |
bool UseExplorer = true) |
--- |
| 1190 |
: CGSCC(CGSCC), DL(M.getDataLayout()), Allocator(Allocator), AG(AG), |
0 |
1190 |
: CGSCC(CGSCC), DL(M.getDataLayout()), Allocator(Allocator), AG(AG), |
0 |
| 1191 |
TargetTriple(M.getTargetTriple()) { |
0 |
1191 |
TargetTriple(M.getTargetTriple()) { |
0 |
| 1192 |
if (UseExplorer) |
0 |
1192 |
if (UseExplorer) |
0 |
| 1193 |
Explorer = new (Allocator) MustBeExecutedContextExplorer( |
0 |
1193 |
Explorer = new (Allocator) MustBeExecutedContextExplorer( |
0 |
| 1194 |
/* ExploreInterBlock */ true, /* ExploreCFGForward */ true, |
--- |
1194 |
/* ExploreInterBlock */ true, /* ExploreCFGForward */ true, |
--- |
| 1195 |
/* ExploreCFGBackward */ true, |
--- |
1195 |
/* ExploreCFGBackward */ true, |
--- |
| 1196 |
/* LIGetter */ |
--- |
1196 |
/* LIGetter */ |
--- |
| 1197 |
[&](const Function &F) { return AG.getAnalysis(F); }, |
0 |
1197 |
[&](const Function &F) { return AG.getAnalysis(F); }, |
0 |
| 1198 |
/* DTGetter */ |
--- |
1198 |
/* DTGetter */ |
--- |
| 1199 |
[&](const Function &F) { |
0 |
1199 |
[&](const Function &F) { |
0 |
| 1200 |
return AG.getAnalysis(F); |
0 |
1200 |
return AG.getAnalysis(F); |
0 |
| 1201 |
}, |
--- |
1201 |
}, |
--- |
| 1202 |
/* PDTGetter */ |
--- |
1202 |
/* PDTGetter */ |
--- |
| 1203 |
[&](const Function &F) { |
0 |
1203 |
[&](const Function &F) { |
0 |
| 1204 |
return AG.getAnalysis(F); |
0 |
1204 |
return AG.getAnalysis(F); |
0 |
| 1205 |
}); |
0 |
1205 |
}); |
0 |
| 1206 |
} |
0 |
1206 |
} |
0 |
| 1207 |
|
--- |
1207 |
|
--- |
| 1208 |
~InformationCache() { |
0 |
1208 |
~InformationCache() { |
0 |
| 1209 |
// The FunctionInfo objects are allocated via a BumpPtrAllocator, we call |
--- |
1209 |
// The FunctionInfo objects are allocated via a BumpPtrAllocator, we call |
--- |
| 1210 |
// the destructor manually. |
--- |
1210 |
// the destructor manually. |
--- |
| 1211 |
for (auto &It : FuncInfoMap) |
0 |
1211 |
for (auto &It : FuncInfoMap) |
0 |
| 1212 |
It.getSecond()->~FunctionInfo(); |
0 |
1212 |
It.getSecond()->~FunctionInfo(); |
0 |
| 1213 |
// Same is true for the instruction exclusions sets. |
--- |
1213 |
// Same is true for the instruction exclusions sets. |
--- |
| 1214 |
using AA::InstExclusionSetTy; |
--- |
1214 |
using AA::InstExclusionSetTy; |
--- |
| 1215 |
for (auto *BES : BESets) |
0 |
1215 |
for (auto *BES : BESets) |
0 |
| 1216 |
BES->~InstExclusionSetTy(); |
0 |
1216 |
BES->~InstExclusionSetTy(); |
0 |
| 1217 |
if (Explorer) |
0 |
1217 |
if (Explorer) |
0 |
| 1218 |
Explorer->~MustBeExecutedContextExplorer(); |
0 |
1218 |
Explorer->~MustBeExecutedContextExplorer(); |
0 |
| 1219 |
} |
0 |
1219 |
} |
0 |
| 1220 |
|
--- |
1220 |
|
--- |
| 1221 |
/// Apply \p CB to all uses of \p F. If \p LookThroughConstantExprUses is |
--- |
1221 |
/// Apply \p CB to all uses of \p F. If \p LookThroughConstantExprUses is |
--- |
| 1222 |
/// true, constant expression users are not given to \p CB but their uses are |
--- |
1222 |
/// true, constant expression users are not given to \p CB but their uses are |
--- |
| 1223 |
/// traversed transitively. |
--- |
1223 |
/// traversed transitively. |
--- |
| 1224 |
template |
--- |
1224 |
template |
--- |
| 1225 |
static void foreachUse(Function &F, CBTy CB, |
--- |
1225 |
static void foreachUse(Function &F, CBTy CB, |
--- |
| 1226 |
bool LookThroughConstantExprUses = true) { |
--- |
1226 |
bool LookThroughConstantExprUses = true) { |
--- |
| 1227 |
SmallVector |
--- |
1227 |
SmallVector |
--- |
| 1228 |
|
--- |
1228 |
|
--- |
| 1229 |
for (unsigned Idx = 0; Idx < Worklist.size(); ++Idx) { |
--- |
1229 |
for (unsigned Idx = 0; Idx < Worklist.size(); ++Idx) { |
--- |
| 1230 |
Use &U = *Worklist[Idx]; |
--- |
1230 |
Use &U = *Worklist[Idx]; |
--- |
| 1231 |
|
--- |
1231 |
|
--- |
| 1232 |
// Allow use in constant bitcasts and simply look through them. |
--- |
1232 |
// Allow use in constant bitcasts and simply look through them. |
--- |
| 1233 |
if (LookThroughConstantExprUses && isa(U.getUser())) { |
--- |
1233 |
if (LookThroughConstantExprUses && isa(U.getUser())) { |
--- |
| 1234 |
for (Use &CEU : cast(U.getUser())->uses()) |
--- |
1234 |
for (Use &CEU : cast(U.getUser())->uses()) |
--- |
| 1235 |
Worklist.push_back(&CEU); |
--- |
1235 |
Worklist.push_back(&CEU); |
--- |
| 1236 |
continue; |
--- |
1236 |
continue; |
--- |
| 1237 |
} |
--- |
1237 |
} |
--- |
| 1238 |
|
--- |
1238 |
|
--- |
| 1239 |
CB(U); |
--- |
1239 |
CB(U); |
--- |
| 1240 |
} |
--- |
1240 |
} |
--- |
| 1241 |
} |
--- |
1241 |
} |
--- |
| 1242 |
|
--- |
1242 |
|
--- |
| 1243 |
/// The CG-SCC the pass is run on, or nullptr if it is a module pass. |
--- |
1243 |
/// The CG-SCC the pass is run on, or nullptr if it is a module pass. |
--- |
| 1244 |
const SetVector *const CGSCC = nullptr; |
--- |
1244 |
const SetVector *const CGSCC = nullptr; |
--- |
| 1245 |
|
--- |
1245 |
|
--- |
| 1246 |
/// A vector type to hold instructions. |
--- |
1246 |
/// A vector type to hold instructions. |
--- |
| 1247 |
using InstructionVectorTy = SmallVector; |
--- |
1247 |
using InstructionVectorTy = SmallVector; |
--- |
| 1248 |
|
--- |
1248 |
|
--- |
| 1249 |
/// A map type from opcodes to instructions with this opcode. |
--- |
1249 |
/// A map type from opcodes to instructions with this opcode. |
--- |
| 1250 |
using OpcodeInstMapTy = DenseMap; |
--- |
1250 |
using OpcodeInstMapTy = DenseMap; |
--- |
| 1251 |
|
--- |
1251 |
|
--- |
| 1252 |
/// Return the map that relates "interesting" opcodes with all instructions |
--- |
1252 |
/// Return the map that relates "interesting" opcodes with all instructions |
--- |
| 1253 |
/// with that opcode in \p F. |
--- |
1253 |
/// with that opcode in \p F. |
--- |
| 1254 |
OpcodeInstMapTy &getOpcodeInstMapForFunction(const Function &F) { |
0 |
1254 |
OpcodeInstMapTy &getOpcodeInstMapForFunction(const Function &F) { |
0 |
| 1255 |
return getFunctionInfo(F).OpcodeInstMap; |
0 |
1255 |
return getFunctionInfo(F).OpcodeInstMap; |
0 |
| 1256 |
} |
--- |
1256 |
} |
--- |
| 1257 |
|
--- |
1257 |
|
--- |
| 1258 |
/// Return the instructions in \p F that may read or write memory. |
--- |
1258 |
/// Return the instructions in \p F that may read or write memory. |
--- |
| 1259 |
InstructionVectorTy &getReadOrWriteInstsForFunction(const Function &F) { |
0 |
1259 |
InstructionVectorTy &getReadOrWriteInstsForFunction(const Function &F) { |
0 |
| 1260 |
return getFunctionInfo(F).RWInsts; |
0 |
1260 |
return getFunctionInfo(F).RWInsts; |
0 |
| 1261 |
} |
--- |
1261 |
} |
--- |
| 1262 |
|
--- |
1262 |
|
--- |
| 1263 |
/// Return MustBeExecutedContextExplorer |
--- |
1263 |
/// Return MustBeExecutedContextExplorer |
--- |
| 1264 |
MustBeExecutedContextExplorer *getMustBeExecutedContextExplorer() { |
0 |
1264 |
MustBeExecutedContextExplorer *getMustBeExecutedContextExplorer() { |
0 |
| 1265 |
return Explorer; |
0 |
1265 |
return Explorer; |
0 |
| 1266 |
} |
--- |
1266 |
} |
--- |
| 1267 |
|
--- |
1267 |
|
--- |
| 1268 |
/// Return TargetLibraryInfo for function \p F. |
--- |
1268 |
/// Return TargetLibraryInfo for function \p F. |
--- |
| 1269 |
TargetLibraryInfo *getTargetLibraryInfoForFunction(const Function &F) { |
0 |
1269 |
TargetLibraryInfo *getTargetLibraryInfoForFunction(const Function &F) { |
0 |
| 1270 |
return AG.getAnalysis(F); |
0 |
1270 |
return AG.getAnalysis(F); |
0 |
| 1271 |
} |
--- |
1271 |
} |
--- |
| 1272 |
|
--- |
1272 |
|
--- |
| 1273 |
/// Return true if \p Arg is involved in a must-tail call, thus the argument |
--- |
1273 |
/// Return true if \p Arg is involved in a must-tail call, thus the argument |
--- |
| 1274 |
/// of the caller or callee. |
--- |
1274 |
/// of the caller or callee. |
--- |
| 1275 |
bool isInvolvedInMustTailCall(const Argument &Arg) { |
--- |
1275 |
bool isInvolvedInMustTailCall(const Argument &Arg) { |
--- |
| 1276 |
FunctionInfo &FI = getFunctionInfo(*Arg.getParent()); |
--- |
1276 |
FunctionInfo &FI = getFunctionInfo(*Arg.getParent()); |
--- |
| 1277 |
return FI.CalledViaMustTail || FI.ContainsMustTailCall; |
--- |
1277 |
return FI.CalledViaMustTail || FI.ContainsMustTailCall; |
--- |
| 1278 |
} |
--- |
1278 |
} |
--- |
| 1279 |
|
--- |
1279 |
|
--- |
| 1280 |
bool isOnlyUsedByAssume(const Instruction &I) const { |
--- |
1280 |
bool isOnlyUsedByAssume(const Instruction &I) const { |
--- |
| 1281 |
return AssumeOnlyValues.contains(&I); |
--- |
1281 |
return AssumeOnlyValues.contains(&I); |
--- |
| 1282 |
} |
--- |
1282 |
} |
--- |
| 1283 |
|
--- |
1283 |
|
--- |
| 1284 |
/// Return the analysis result from a pass \p AP for function \p F. |
--- |
1284 |
/// Return the analysis result from a pass \p AP for function \p F. |
--- |
| 1285 |
template |
--- |
1285 |
template |
--- |
| 1286 |
typename AP::Result *getAnalysisResultForFunction(const Function &F, |
0 |
1286 |
typename AP::Result *getAnalysisResultForFunction(const Function &F, |
0 |
| 1287 |
bool CachedOnly = false) { |
--- |
1287 |
bool CachedOnly = false) { |
--- |
| 1288 |
return AG.getAnalysis(F, CachedOnly); |
0 |
1288 |
return AG.getAnalysis(F, CachedOnly); |
0 |
| 1289 |
} |
--- |
1289 |
} |
--- |
| 1290 |
|
--- |
1290 |
|
--- |
| 1291 |
/// Return datalayout used in the module. |
--- |
1291 |
/// Return datalayout used in the module. |
--- |
| 1292 |
const DataLayout &getDL() { return DL; } |
--- |
1292 |
const DataLayout &getDL() { return DL; } |
--- |
| 1293 |
|
--- |
1293 |
|
--- |
| 1294 |
/// Return the map conaining all the knowledge we have from `llvm.assume`s. |
--- |
1294 |
/// Return the map conaining all the knowledge we have from `llvm.assume`s. |
--- |
| 1295 |
const RetainedKnowledgeMap &getKnowledgeMap() const { return KnowledgeMap; } |
0 |
1295 |
const RetainedKnowledgeMap &getKnowledgeMap() const { return KnowledgeMap; } |
0 |
| 1296 |
|
--- |
1296 |
|
--- |
| 1297 |
/// Given \p BES, return a uniqued version. |
--- |
1297 |
/// Given \p BES, return a uniqued version. |
--- |
| 1298 |
const AA::InstExclusionSetTy * |
--- |
1298 |
const AA::InstExclusionSetTy * |
--- |
| 1299 |
getOrCreateUniqueBlockExecutionSet(const AA::InstExclusionSetTy *BES) { |
--- |
1299 |
getOrCreateUniqueBlockExecutionSet(const AA::InstExclusionSetTy *BES) { |
--- |
| 1300 |
auto It = BESets.find(BES); |
--- |
1300 |
auto It = BESets.find(BES); |
--- |
| 1301 |
if (It != BESets.end()) |
--- |
1301 |
if (It != BESets.end()) |
--- |
| 1302 |
return *It; |
--- |
1302 |
return *It; |
--- |
| 1303 |
auto *UniqueBES = new (Allocator) AA::InstExclusionSetTy(*BES); |
--- |
1303 |
auto *UniqueBES = new (Allocator) AA::InstExclusionSetTy(*BES); |
--- |
| 1304 |
bool Success = BESets.insert(UniqueBES).second; |
--- |
1304 |
bool Success = BESets.insert(UniqueBES).second; |
--- |
| 1305 |
(void)Success; |
--- |
1305 |
(void)Success; |
--- |
| 1306 |
assert(Success && "Expected only new entries to be added"); |
--- |
1306 |
assert(Success && "Expected only new entries to be added"); |
--- |
| 1307 |
return UniqueBES; |
--- |
1307 |
return UniqueBES; |
--- |
| 1308 |
} |
--- |
1308 |
} |
--- |
| 1309 |
|
--- |
1309 |
|
--- |
| 1310 |
/// Return true if the stack (llvm::Alloca) can be accessed by other threads. |
--- |
1310 |
/// Return true if the stack (llvm::Alloca) can be accessed by other threads. |
--- |
| 1311 |
bool stackIsAccessibleByOtherThreads() { return !targetIsGPU(); } |
0 |
1311 |
bool stackIsAccessibleByOtherThreads() { return !targetIsGPU(); } |
0 |
| 1312 |
|
--- |
1312 |
|
--- |
| 1313 |
/// Return true if the target is a GPU. |
--- |
1313 |
/// Return true if the target is a GPU. |
--- |
| 1314 |
bool targetIsGPU() { |
0 |
1314 |
bool targetIsGPU() { |
0 |
| 1315 |
return TargetTriple.isAMDGPU() || TargetTriple.isNVPTX(); |
0 |
1315 |
return TargetTriple.isAMDGPU() || TargetTriple.isNVPTX(); |
0 |
| 1316 |
} |
--- |
1316 |
} |
--- |
| 1317 |
|
--- |
1317 |
|
--- |
| 1318 |
private: |
--- |
1318 |
private: |
--- |
| 1319 |
struct FunctionInfo { |
--- |
1319 |
struct FunctionInfo { |
--- |
| 1320 |
~FunctionInfo(); |
--- |
1320 |
~FunctionInfo(); |
--- |
| 1321 |
|
--- |
1321 |
|
--- |
| 1322 |
/// A nested map that remembers all instructions in a function with a |
--- |
1322 |
/// A nested map that remembers all instructions in a function with a |
--- |
| 1323 |
/// certain instruction opcode (Instruction::getOpcode()). |
--- |
1323 |
/// certain instruction opcode (Instruction::getOpcode()). |
--- |
| 1324 |
OpcodeInstMapTy OpcodeInstMap; |
--- |
1324 |
OpcodeInstMapTy OpcodeInstMap; |
--- |
| 1325 |
|
--- |
1325 |
|
--- |
| 1326 |
/// A map from functions to their instructions that may read or write |
--- |
1326 |
/// A map from functions to their instructions that may read or write |
--- |
| 1327 |
/// memory. |
--- |
1327 |
/// memory. |
--- |
| 1328 |
InstructionVectorTy RWInsts; |
--- |
1328 |
InstructionVectorTy RWInsts; |
--- |
| 1329 |
|
--- |
1329 |
|
--- |
| 1330 |
/// Function is called by a `musttail` call. |
--- |
1330 |
/// Function is called by a `musttail` call. |
--- |
| 1331 |
bool CalledViaMustTail; |
--- |
1331 |
bool CalledViaMustTail; |
--- |
| 1332 |
|
--- |
1332 |
|
--- |
| 1333 |
/// Function contains a `musttail` call. |
--- |
1333 |
/// Function contains a `musttail` call. |
--- |
| 1334 |
bool ContainsMustTailCall; |
--- |
1334 |
bool ContainsMustTailCall; |
--- |
| 1335 |
}; |
--- |
1335 |
}; |
--- |
| 1336 |
|
--- |
1336 |
|
--- |
| 1337 |
/// A map type from functions to informatio about it. |
--- |
1337 |
/// A map type from functions to informatio about it. |
--- |
| 1338 |
DenseMap FuncInfoMap; |
--- |
1338 |
DenseMap FuncInfoMap; |
--- |
| 1339 |
|
--- |
1339 |
|
--- |
| 1340 |
/// Return information about the function \p F, potentially by creating it. |
--- |
1340 |
/// Return information about the function \p F, potentially by creating it. |
--- |
| 1341 |
FunctionInfo &getFunctionInfo(const Function &F) { |
0 |
1341 |
FunctionInfo &getFunctionInfo(const Function &F) { |
0 |
| 1342 |
FunctionInfo *&FI = FuncInfoMap[&F]; |
0 |
1342 |
FunctionInfo *&FI = FuncInfoMap[&F]; |
0 |
| 1343 |
if (!FI) { |
0 |
1343 |
if (!FI) { |
0 |
| 1344 |
FI = new (Allocator) FunctionInfo(); |
0 |
1344 |
FI = new (Allocator) FunctionInfo(); |
0 |
| 1345 |
initializeInformationCache(F, *FI); |
0 |
1345 |
initializeInformationCache(F, *FI); |
0 |
| 1346 |
} |
--- |
1346 |
} |
--- |
| 1347 |
return *FI; |
0 |
1347 |
return *FI; |
0 |
| 1348 |
} |
--- |
1348 |
} |
--- |
| 1349 |
|
--- |
1349 |
|
--- |
| 1350 |
/// Initialize the function information cache \p FI for the function \p F. |
--- |
1350 |
/// Initialize the function information cache \p FI for the function \p F. |
--- |
| 1351 |
/// |
--- |
1351 |
/// |
--- |
| 1352 |
/// This method needs to be called for all function that might be looked at |
--- |
1352 |
/// This method needs to be called for all function that might be looked at |
--- |
| 1353 |
/// through the information cache interface *prior* to looking at them. |
--- |
1353 |
/// through the information cache interface *prior* to looking at them. |
--- |
| 1354 |
void initializeInformationCache(const Function &F, FunctionInfo &FI); |
--- |
1354 |
void initializeInformationCache(const Function &F, FunctionInfo &FI); |
--- |
| 1355 |
|
--- |
1355 |
|
--- |
| 1356 |
/// The datalayout used in the module. |
--- |
1356 |
/// The datalayout used in the module. |
--- |
| 1357 |
const DataLayout &DL; |
--- |
1357 |
const DataLayout &DL; |
--- |
| 1358 |
|
--- |
1358 |
|
--- |
| 1359 |
/// The allocator used to allocate memory, e.g. for `FunctionInfo`s. |
--- |
1359 |
/// The allocator used to allocate memory, e.g. for `FunctionInfo`s. |
--- |
| 1360 |
BumpPtrAllocator &Allocator; |
--- |
1360 |
BumpPtrAllocator &Allocator; |
--- |
| 1361 |
|
--- |
1361 |
|
--- |
| 1362 |
/// MustBeExecutedContextExplorer |
--- |
1362 |
/// MustBeExecutedContextExplorer |
--- |
| 1363 |
MustBeExecutedContextExplorer *Explorer = nullptr; |
--- |
1363 |
MustBeExecutedContextExplorer *Explorer = nullptr; |
--- |
| 1364 |
|
--- |
1364 |
|
--- |
| 1365 |
/// A map with knowledge retained in `llvm.assume` instructions. |
--- |
1365 |
/// A map with knowledge retained in `llvm.assume` instructions. |
--- |
| 1366 |
RetainedKnowledgeMap KnowledgeMap; |
--- |
1366 |
RetainedKnowledgeMap KnowledgeMap; |
--- |
| 1367 |
|
--- |
1367 |
|
--- |
| 1368 |
/// A container for all instructions that are only used by `llvm.assume`. |
--- |
1368 |
/// A container for all instructions that are only used by `llvm.assume`. |
--- |
| 1369 |
SetVector AssumeOnlyValues; |
--- |
1369 |
SetVector AssumeOnlyValues; |
--- |
| 1370 |
|
--- |
1370 |
|
--- |
| 1371 |
/// Cache for block sets to allow reuse. |
--- |
1371 |
/// Cache for block sets to allow reuse. |
--- |
| 1372 |
DenseSet BESets; |
--- |
1372 |
DenseSet BESets; |
--- |
| 1373 |
|
--- |
1373 |
|
--- |
| 1374 |
/// Getters for analysis. |
--- |
1374 |
/// Getters for analysis. |
--- |
| 1375 |
AnalysisGetter &AG; |
--- |
1375 |
AnalysisGetter &AG; |
--- |
| 1376 |
|
--- |
1376 |
|
--- |
| 1377 |
/// Set of inlineable functions |
--- |
1377 |
/// Set of inlineable functions |
--- |
| 1378 |
SmallPtrSet InlineableFunctions; |
--- |
1378 |
SmallPtrSet InlineableFunctions; |
--- |
| 1379 |
|
--- |
1379 |
|
--- |
| 1380 |
/// The triple describing the target machine. |
--- |
1380 |
/// The triple describing the target machine. |
--- |
| 1381 |
Triple TargetTriple; |
--- |
1381 |
Triple TargetTriple; |
--- |
| 1382 |
|
--- |
1382 |
|
--- |
| 1383 |
/// Give the Attributor access to the members so |
--- |
1383 |
/// Give the Attributor access to the members so |
--- |
| 1384 |
/// Attributor::identifyDefaultAbstractAttributes(...) can initialize them. |
--- |
1384 |
/// Attributor::identifyDefaultAbstractAttributes(...) can initialize them. |
--- |
| 1385 |
friend struct Attributor; |
--- |
1385 |
friend struct Attributor; |
--- |
| 1386 |
}; |
--- |
1386 |
}; |
--- |
| 1387 |
|
--- |
1387 |
|
--- |
| 1388 |
/// Configuration for the Attributor. |
--- |
1388 |
/// Configuration for the Attributor. |
--- |
| 1389 |
struct AttributorConfig { |
--- |
1389 |
struct AttributorConfig { |
--- |
| 1390 |
|
--- |
1390 |
|
--- |
| 1391 |
AttributorConfig(CallGraphUpdater &CGUpdater) : CGUpdater(CGUpdater) {} |
0 |
1391 |
AttributorConfig(CallGraphUpdater &CGUpdater) : CGUpdater(CGUpdater) {} |
0 |
| 1392 |
|
--- |
1392 |
|
--- |
| 1393 |
/// Is the user of the Attributor a module pass or not. This determines what |
--- |
1393 |
/// Is the user of the Attributor a module pass or not. This determines what |
--- |
| 1394 |
/// IR we can look at and modify. If it is a module pass we might deduce facts |
--- |
1394 |
/// IR we can look at and modify. If it is a module pass we might deduce facts |
--- |
| 1395 |
/// outside the initial function set and modify functions outside that set, |
--- |
1395 |
/// outside the initial function set and modify functions outside that set, |
--- |
| 1396 |
/// but only as part of the optimization of the functions in the initial |
--- |
1396 |
/// but only as part of the optimization of the functions in the initial |
--- |
| 1397 |
/// function set. For CGSCC passes we can look at the IR of the module slice |
--- |
1397 |
/// function set. For CGSCC passes we can look at the IR of the module slice |
--- |
| 1398 |
/// but never run any deduction, or perform any modification, outside the |
--- |
1398 |
/// but never run any deduction, or perform any modification, outside the |
--- |
| 1399 |
/// initial function set (which we assume is the SCC). |
--- |
1399 |
/// initial function set (which we assume is the SCC). |
--- |
| 1400 |
bool IsModulePass = true; |
--- |
1400 |
bool IsModulePass = true; |
--- |
| 1401 |
|
--- |
1401 |
|
--- |
| 1402 |
/// Flag to determine if we can delete functions or keep dead ones around. |
--- |
1402 |
/// Flag to determine if we can delete functions or keep dead ones around. |
--- |
| 1403 |
bool DeleteFns = true; |
--- |
1403 |
bool DeleteFns = true; |
--- |
| 1404 |
|
--- |
1404 |
|
--- |
| 1405 |
/// Flag to determine if we rewrite function signatures. |
--- |
1405 |
/// Flag to determine if we rewrite function signatures. |
--- |
| 1406 |
bool RewriteSignatures = true; |
--- |
1406 |
bool RewriteSignatures = true; |
--- |
| 1407 |
|
--- |
1407 |
|
--- |
| 1408 |
/// Flag to determine if we want to initialize all default AAs for an internal |
--- |
1408 |
/// Flag to determine if we want to initialize all default AAs for an internal |
--- |
| 1409 |
/// function marked live. See also: InitializationCallback> |
--- |
1409 |
/// function marked live. See also: InitializationCallback> |
--- |
| 1410 |
bool DefaultInitializeLiveInternals = true; |
--- |
1410 |
bool DefaultInitializeLiveInternals = true; |
--- |
| 1411 |
|
--- |
1411 |
|
--- |
| 1412 |
/// Flag to determine if we should skip all liveness checks early on. |
--- |
1412 |
/// Flag to determine if we should skip all liveness checks early on. |
--- |
| 1413 |
bool UseLiveness = true; |
--- |
1413 |
bool UseLiveness = true; |
--- |
| 1414 |
|
--- |
1414 |
|
--- |
| 1415 |
/// Callback function to be invoked on internal functions marked live. |
--- |
1415 |
/// Callback function to be invoked on internal functions marked live. |
--- |
| 1416 |
std::function InitializationCallback = |
--- |
1416 |
std::function InitializationCallback = |
--- |
| 1417 |
nullptr; |
--- |
1417 |
nullptr; |
--- |
| 1418 |
|
--- |
1418 |
|
--- |
| 1419 |
/// Helper to update an underlying call graph and to delete functions. |
--- |
1419 |
/// Helper to update an underlying call graph and to delete functions. |
--- |
| 1420 |
CallGraphUpdater &CGUpdater; |
--- |
1420 |
CallGraphUpdater &CGUpdater; |
--- |
| 1421 |
|
--- |
1421 |
|
--- |
| 1422 |
/// If not null, a set limiting the attribute opportunities. |
--- |
1422 |
/// If not null, a set limiting the attribute opportunities. |
--- |
| 1423 |
DenseSet *Allowed = nullptr; |
--- |
1423 |
DenseSet *Allowed = nullptr; |
--- |
| 1424 |
|
--- |
1424 |
|
--- |
| 1425 |
/// Maximum number of iterations to run until fixpoint. |
--- |
1425 |
/// Maximum number of iterations to run until fixpoint. |
--- |
| 1426 |
std::optional MaxFixpointIterations; |
--- |
1426 |
std::optional MaxFixpointIterations; |
--- |
| 1427 |
|
--- |
1427 |
|
--- |
| 1428 |
/// A callback function that returns an ORE object from a Function pointer. |
--- |
1428 |
/// A callback function that returns an ORE object from a Function pointer. |
--- |
| 1429 |
///{ |
--- |
1429 |
///{ |
--- |
| 1430 |
using OptimizationRemarkGetter = |
--- |
1430 |
using OptimizationRemarkGetter = |
--- |
| 1431 |
function_ref; |
--- |
1431 |
function_ref; |
--- |
| 1432 |
OptimizationRemarkGetter OREGetter = nullptr; |
--- |
1432 |
OptimizationRemarkGetter OREGetter = nullptr; |
--- |
| 1433 |
///} |
--- |
1433 |
///} |
--- |
| 1434 |
|
--- |
1434 |
|
--- |
| 1435 |
/// The name of the pass running the attributor, used to emit remarks. |
--- |
1435 |
/// The name of the pass running the attributor, used to emit remarks. |
--- |
| 1436 |
const char *PassName = nullptr; |
--- |
1436 |
const char *PassName = nullptr; |
--- |
| 1437 |
|
--- |
1437 |
|
--- |
| 1438 |
using IPOAmendableCBTy = function_ref; |
--- |
1438 |
using IPOAmendableCBTy = function_ref; |
--- |
| 1439 |
IPOAmendableCBTy IPOAmendableCB; |
--- |
1439 |
IPOAmendableCBTy IPOAmendableCB; |
--- |
| 1440 |
}; |
--- |
1440 |
}; |
--- |
| 1441 |
|
--- |
1441 |
|
--- |
| 1442 |
/// The fixpoint analysis framework that orchestrates the attribute deduction. |
--- |
1442 |
/// The fixpoint analysis framework that orchestrates the attribute deduction. |
--- |
| 1443 |
/// |
--- |
1443 |
/// |
--- |
| 1444 |
/// The Attributor provides a general abstract analysis framework (guided |
--- |
1444 |
/// The Attributor provides a general abstract analysis framework (guided |
--- |
| 1445 |
/// fixpoint iteration) as well as helper functions for the deduction of |
--- |
1445 |
/// fixpoint iteration) as well as helper functions for the deduction of |
--- |
| 1446 |
/// (LLVM-IR) attributes. However, also other code properties can be deduced, |
--- |
1446 |
/// (LLVM-IR) attributes. However, also other code properties can be deduced, |
--- |
| 1447 |
/// propagated, and ultimately manifested through the Attributor framework. This |
--- |
1447 |
/// propagated, and ultimately manifested through the Attributor framework. This |
--- |
| 1448 |
/// is particularly useful if these properties interact with attributes and a |
--- |
1448 |
/// is particularly useful if these properties interact with attributes and a |
--- |
| 1449 |
/// co-scheduled deduction allows to improve the solution. Even if not, thus if |
--- |
1449 |
/// co-scheduled deduction allows to improve the solution. Even if not, thus if |
--- |
| 1450 |
/// attributes/properties are completely isolated, they should use the |
--- |
1450 |
/// attributes/properties are completely isolated, they should use the |
--- |
| 1451 |
/// Attributor framework to reduce the number of fixpoint iteration frameworks |
--- |
1451 |
/// Attributor framework to reduce the number of fixpoint iteration frameworks |
--- |
| 1452 |
/// in the code base. Note that the Attributor design makes sure that isolated |
--- |
1452 |
/// in the code base. Note that the Attributor design makes sure that isolated |
--- |
| 1453 |
/// attributes are not impacted, in any way, by others derived at the same time |
--- |
1453 |
/// attributes are not impacted, in any way, by others derived at the same time |
--- |
| 1454 |
/// if there is no cross-reasoning performed. |
--- |
1454 |
/// if there is no cross-reasoning performed. |
--- |
| 1455 |
/// |
--- |
1455 |
/// |
--- |
| 1456 |
/// The public facing interface of the Attributor is kept simple and basically |
--- |
1456 |
/// The public facing interface of the Attributor is kept simple and basically |
--- |
| 1457 |
/// allows abstract attributes to one thing, query abstract attributes |
--- |
1457 |
/// allows abstract attributes to one thing, query abstract attributes |
--- |
| 1458 |
/// in-flight. There are two reasons to do this: |
--- |
1458 |
/// in-flight. There are two reasons to do this: |
--- |
| 1459 |
/// a) The optimistic state of one abstract attribute can justify an |
--- |
1459 |
/// a) The optimistic state of one abstract attribute can justify an |
--- |
| 1460 |
/// optimistic state of another, allowing to framework to end up with an |
--- |
1460 |
/// optimistic state of another, allowing to framework to end up with an |
--- |
| 1461 |
/// optimistic (=best possible) fixpoint instead of one based solely on |
--- |
1461 |
/// optimistic (=best possible) fixpoint instead of one based solely on |
--- |
| 1462 |
/// information in the IR. |
--- |
1462 |
/// information in the IR. |
--- |
| 1463 |
/// b) This avoids reimplementing various kinds of lookups, e.g., to check |
--- |
1463 |
/// b) This avoids reimplementing various kinds of lookups, e.g., to check |
--- |
| 1464 |
/// for existing IR attributes, in favor of a single lookups interface |
--- |
1464 |
/// for existing IR attributes, in favor of a single lookups interface |
--- |
| 1465 |
/// provided by an abstract attribute subclass. |
--- |
1465 |
/// provided by an abstract attribute subclass. |
--- |
| 1466 |
/// |
--- |
1466 |
/// |
--- |
| 1467 |
/// NOTE: The mechanics of adding a new "concrete" abstract attribute are |
--- |
1467 |
/// NOTE: The mechanics of adding a new "concrete" abstract attribute are |
--- |
| 1468 |
/// described in the file comment. |
--- |
1468 |
/// described in the file comment. |
--- |
| 1469 |
struct Attributor { |
--- |
1469 |
struct Attributor { |
--- |
| 1470 |
|
--- |
1470 |
|
--- |
| 1471 |
/// Constructor |
--- |
1471 |
/// Constructor |
--- |
| 1472 |
/// |
--- |
1472 |
/// |
--- |
| 1473 |
/// \param Functions The set of functions we are deriving attributes for. |
--- |
1473 |
/// \param Functions The set of functions we are deriving attributes for. |
--- |
| 1474 |
/// \param InfoCache Cache to hold various information accessible for |
--- |
1474 |
/// \param InfoCache Cache to hold various information accessible for |
--- |
| 1475 |
/// the abstract attributes. |
--- |
1475 |
/// the abstract attributes. |
--- |
| 1476 |
/// \param Configuration The Attributor configuration which determines what |
--- |
1476 |
/// \param Configuration The Attributor configuration which determines what |
--- |
| 1477 |
/// generic features to use. |
--- |
1477 |
/// generic features to use. |
--- |
| 1478 |
Attributor(SetVector &Functions, InformationCache &InfoCache, |
0 |
1478 |
Attributor(SetVector &Functions, InformationCache &InfoCache, |
0 |
| 1479 |
AttributorConfig Configuration) |
--- |
1479 |
AttributorConfig Configuration) |
--- |
| 1480 |
: Allocator(InfoCache.Allocator), Functions(Functions), |
0 |
1480 |
: Allocator(InfoCache.Allocator), Functions(Functions), |
0 |
| 1481 |
InfoCache(InfoCache), Configuration(Configuration) {} |
0 |
1481 |
InfoCache(InfoCache), Configuration(Configuration) {} |
0 |
| 1482 |
|
--- |
1482 |
|
--- |
| 1483 |
~Attributor(); |
--- |
1483 |
~Attributor(); |
--- |
| 1484 |
|
--- |
1484 |
|
--- |
| 1485 |
/// Run the analyses until a fixpoint is reached or enforced (timeout). |
--- |
1485 |
/// Run the analyses until a fixpoint is reached or enforced (timeout). |
--- |
| 1486 |
/// |
--- |
1486 |
/// |
--- |
| 1487 |
/// The attributes registered with this Attributor can be used after as long |
--- |
1487 |
/// The attributes registered with this Attributor can be used after as long |
--- |
| 1488 |
/// as the Attributor is not destroyed (it owns the attributes now). |
--- |
1488 |
/// as the Attributor is not destroyed (it owns the attributes now). |
--- |
| 1489 |
/// |
--- |
1489 |
/// |
--- |
| 1490 |
/// \Returns CHANGED if the IR was changed, otherwise UNCHANGED. |
--- |
1490 |
/// \Returns CHANGED if the IR was changed, otherwise UNCHANGED. |
--- |
| 1491 |
ChangeStatus run(); |
--- |
1491 |
ChangeStatus run(); |
--- |
| 1492 |
|
--- |
1492 |
|
--- |
| 1493 |
/// Lookup an abstract attribute of type \p AAType at position \p IRP. While |
--- |
1493 |
/// Lookup an abstract attribute of type \p AAType at position \p IRP. While |
--- |
| 1494 |
/// no abstract attribute is found equivalent positions are checked, see |
--- |
1494 |
/// no abstract attribute is found equivalent positions are checked, see |
--- |
| 1495 |
/// SubsumingPositionIterator. Thus, the returned abstract attribute |
--- |
1495 |
/// SubsumingPositionIterator. Thus, the returned abstract attribute |
--- |
| 1496 |
/// might be anchored at a different position, e.g., the callee if \p IRP is a |
--- |
1496 |
/// might be anchored at a different position, e.g., the callee if \p IRP is a |
--- |
| 1497 |
/// call base. |
--- |
1497 |
/// call base. |
--- |
| 1498 |
/// |
--- |
1498 |
/// |
--- |
| 1499 |
/// This method is the only (supported) way an abstract attribute can retrieve |
--- |
1499 |
/// This method is the only (supported) way an abstract attribute can retrieve |
--- |
| 1500 |
/// information from another abstract attribute. As an example, take an |
--- |
1500 |
/// information from another abstract attribute. As an example, take an |
--- |
| 1501 |
/// abstract attribute that determines the memory access behavior for a |
--- |
1501 |
/// abstract attribute that determines the memory access behavior for a |
--- |
| 1502 |
/// argument (readnone, readonly, ...). It should use `getAAFor` to get the |
--- |
1502 |
/// argument (readnone, readonly, ...). It should use `getAAFor` to get the |
--- |
| 1503 |
/// most optimistic information for other abstract attributes in-flight, e.g. |
--- |
1503 |
/// most optimistic information for other abstract attributes in-flight, e.g. |
--- |
| 1504 |
/// the one reasoning about the "captured" state for the argument or the one |
--- |
1504 |
/// the one reasoning about the "captured" state for the argument or the one |
--- |
| 1505 |
/// reasoning on the memory access behavior of the function as a whole. |
--- |
1505 |
/// reasoning on the memory access behavior of the function as a whole. |
--- |
| 1506 |
/// |
--- |
1506 |
/// |
--- |
| 1507 |
/// If the DepClass enum is set to `DepClassTy::None` the dependence from |
--- |
1507 |
/// If the DepClass enum is set to `DepClassTy::None` the dependence from |
--- |
| 1508 |
/// \p QueryingAA to the return abstract attribute is not automatically |
--- |
1508 |
/// \p QueryingAA to the return abstract attribute is not automatically |
--- |
| 1509 |
/// recorded. This should only be used if the caller will record the |
--- |
1509 |
/// recorded. This should only be used if the caller will record the |
--- |
| 1510 |
/// dependence explicitly if necessary, thus if it the returned abstract |
--- |
1510 |
/// dependence explicitly if necessary, thus if it the returned abstract |
--- |
| 1511 |
/// attribute is used for reasoning. To record the dependences explicitly use |
--- |
1511 |
/// attribute is used for reasoning. To record the dependences explicitly use |
--- |
| 1512 |
/// the `Attributor::recordDependence` method. |
--- |
1512 |
/// the `Attributor::recordDependence` method. |
--- |
| 1513 |
template |
--- |
1513 |
template |
--- |
| 1514 |
const AAType *getAAFor(const AbstractAttribute &QueryingAA, |
0 |
1514 |
const AAType *getAAFor(const AbstractAttribute &QueryingAA, |
0 |
| 1515 |
const IRPosition &IRP, DepClassTy DepClass) { |
--- |
1515 |
const IRPosition &IRP, DepClassTy DepClass) { |
--- |
| 1516 |
return getOrCreateAAFor(IRP, &QueryingAA, DepClass, |
0 |
1516 |
return getOrCreateAAFor(IRP, &QueryingAA, DepClass, |
0 |
| 1517 |
/* ForceUpdate */ false); |
0 |
1517 |
/* ForceUpdate */ false); |
0 |
| 1518 |
} |
--- |
1518 |
} |
--- |
| 1519 |
|
--- |
1519 |
|
--- |
| 1520 |
/// Similar to getAAFor but the return abstract attribute will be updated (via |
--- |
1520 |
/// Similar to getAAFor but the return abstract attribute will be updated (via |
--- |
| 1521 |
/// `AbstractAttribute::update`) even if it is found in the cache. This is |
--- |
1521 |
/// `AbstractAttribute::update`) even if it is found in the cache. This is |
--- |
| 1522 |
/// especially useful for AAIsDead as changes in liveness can make updates |
--- |
1522 |
/// especially useful for AAIsDead as changes in liveness can make updates |
--- |
| 1523 |
/// possible/useful that were not happening before as the abstract attribute |
--- |
1523 |
/// possible/useful that were not happening before as the abstract attribute |
--- |
| 1524 |
/// was assumed dead. |
--- |
1524 |
/// was assumed dead. |
--- |
| 1525 |
template |
--- |
1525 |
template |
--- |
| 1526 |
const AAType *getAndUpdateAAFor(const AbstractAttribute &QueryingAA, |
--- |
1526 |
const AAType *getAndUpdateAAFor(const AbstractAttribute &QueryingAA, |
--- |
| 1527 |
const IRPosition &IRP, DepClassTy DepClass) { |
--- |
1527 |
const IRPosition &IRP, DepClassTy DepClass) { |
--- |
| 1528 |
return getOrCreateAAFor(IRP, &QueryingAA, DepClass, |
--- |
1528 |
return getOrCreateAAFor(IRP, &QueryingAA, DepClass, |
--- |
| 1529 |
/* ForceUpdate */ true); |
--- |
1529 |
/* ForceUpdate */ true); |
--- |
| 1530 |
} |
--- |
1530 |
} |
--- |
| 1531 |
|
--- |
1531 |
|
--- |
| 1532 |
/// The version of getAAFor that allows to omit a querying abstract |
--- |
1532 |
/// The version of getAAFor that allows to omit a querying abstract |
--- |
| 1533 |
/// attribute. Using this after Attributor started running is restricted to |
--- |
1533 |
/// attribute. Using this after Attributor started running is restricted to |
--- |
| 1534 |
/// only the Attributor itself. Initial seeding of AAs can be done via this |
--- |
1534 |
/// only the Attributor itself. Initial seeding of AAs can be done via this |
--- |
| 1535 |
/// function. |
--- |
1535 |
/// function. |
--- |
| 1536 |
/// NOTE: ForceUpdate is ignored in any stage other than the update stage. |
--- |
1536 |
/// NOTE: ForceUpdate is ignored in any stage other than the update stage. |
--- |
| 1537 |
template |
--- |
1537 |
template |
--- |
| 1538 |
const AAType *getOrCreateAAFor(IRPosition IRP, |
0 |
1538 |
const AAType *getOrCreateAAFor(IRPosition IRP, |
0 |
| 1539 |
const AbstractAttribute *QueryingAA, |
--- |
1539 |
const AbstractAttribute *QueryingAA, |
--- |
| 1540 |
DepClassTy DepClass, bool ForceUpdate = false, |
--- |
1540 |
DepClassTy DepClass, bool ForceUpdate = false, |
--- |
| 1541 |
bool UpdateAfterInit = true) { |
--- |
1541 |
bool UpdateAfterInit = true) { |
--- |
| 1542 |
if (!shouldPropagateCallBaseContext(IRP)) |
0 |
1542 |
if (!shouldPropagateCallBaseContext(IRP)) |
0 |
| 1543 |
IRP = IRP.stripCallBaseContext(); |
0 |
1543 |
IRP = IRP.stripCallBaseContext(); |
0 |
| 1544 |
|
--- |
1544 |
|
--- |
| 1545 |
if (AAType *AAPtr = lookupAAFor(IRP, QueryingAA, DepClass, |
0 |
1545 |
if (AAType *AAPtr = lookupAAFor(IRP, QueryingAA, DepClass, |
0 |
| 1546 |
/* AllowInvalidState */ true)) { |
--- |
1546 |
/* AllowInvalidState */ true)) { |
--- |
| 1547 |
if (ForceUpdate && Phase == AttributorPhase::UPDATE) |
0 |
1547 |
if (ForceUpdate && Phase == AttributorPhase::UPDATE) |
0 |
| 1548 |
updateAA(*AAPtr); |
0 |
1548 |
updateAA(*AAPtr); |
0 |
| 1549 |
return AAPtr; |
0 |
1549 |
return AAPtr; |
0 |
| 1550 |
} |
--- |
1550 |
} |
--- |
| 1551 |
|
--- |
1551 |
|
--- |
| 1552 |
bool ShouldUpdateAA; |
--- |
1552 |
bool ShouldUpdateAA; |
--- |
| 1553 |
if (!shouldInitialize(IRP, ShouldUpdateAA)) |
0 |
1553 |
if (!shouldInitialize(IRP, ShouldUpdateAA)) |
0 |
| 1554 |
return nullptr; |
0 |
1554 |
return nullptr; |
0 |
| 1555 |
|
--- |
1555 |
|
--- |
| 1556 |
// No matching attribute found, create one. |
--- |
1556 |
// No matching attribute found, create one. |
--- |
| 1557 |
// Use the static create method. |
--- |
1557 |
// Use the static create method. |
--- |
| 1558 |
auto &AA = AAType::createForPosition(IRP, *this); |
0 |
1558 |
auto &AA = AAType::createForPosition(IRP, *this); |
0 |
| 1559 |
|
--- |
1559 |
|
--- |
| 1560 |
// Always register a new attribute to make sure we clean up the allocated |
--- |
1560 |
// Always register a new attribute to make sure we clean up the allocated |
--- |
| 1561 |
// memory properly. |
--- |
1561 |
// memory properly. |
--- |
| 1562 |
registerAA(AA); |
0 |
1562 |
registerAA(AA); |
0 |
| 1563 |
|
--- |
1563 |
|
--- |
| 1564 |
// If we are currenty seeding attributes, enforce seeding rules. |
--- |
1564 |
// If we are currenty seeding attributes, enforce seeding rules. |
--- |
| 1565 |
if (Phase == AttributorPhase::SEEDING && !shouldSeedAttribute(AA)) { |
0 |
1565 |
if (Phase == AttributorPhase::SEEDING && !shouldSeedAttribute(AA)) { |
0 |
| 1566 |
AA.getState().indicatePessimisticFixpoint(); |
0 |
1566 |
AA.getState().indicatePessimisticFixpoint(); |
0 |
| 1567 |
return &AA; |
0 |
1567 |
return &AA; |
0 |
| 1568 |
} |
--- |
1568 |
} |
--- |
| 1569 |
|
--- |
1569 |
|
--- |
| 1570 |
// Bootstrap the new attribute with an initial update to propagate |
--- |
1570 |
// Bootstrap the new attribute with an initial update to propagate |
--- |
| 1571 |
// information, e.g., function -> call site. |
--- |
1571 |
// information, e.g., function -> call site. |
--- |
| 1572 |
{ |
--- |
1572 |
{ |
--- |
| 1573 |
TimeTraceScope TimeScope("initialize", [&]() { |
0 |
1573 |
TimeTraceScope TimeScope("initialize", [&]() { |
0 |
| 1574 |
return AA.getName() + |
0 |
1574 |
return AA.getName() + |
0 |
| 1575 |
std::to_string(AA.getIRPosition().getPositionKind()); |
0 |
1575 |
std::to_string(AA.getIRPosition().getPositionKind()); |
0 |
| 1576 |
}); |
--- |
1576 |
}); |
--- |
| 1577 |
++InitializationChainLength; |
0 |
1577 |
++InitializationChainLength; |
0 |
| 1578 |
AA.initialize(*this); |
0 |
1578 |
AA.initialize(*this); |
0 |
| 1579 |
--InitializationChainLength; |
0 |
1579 |
--InitializationChainLength; |
0 |
| 1580 |
} |
0 |
1580 |
} |
0 |
| 1581 |
|
--- |
1581 |
|
--- |
| 1582 |
if (!ShouldUpdateAA) { |
0 |
1582 |
if (!ShouldUpdateAA) { |
0 |
| 1583 |
AA.getState().indicatePessimisticFixpoint(); |
0 |
1583 |
AA.getState().indicatePessimisticFixpoint(); |
0 |
| 1584 |
return &AA; |
0 |
1584 |
return &AA; |
0 |
| 1585 |
} |
--- |
1585 |
} |
--- |
| 1586 |
|
--- |
1586 |
|
--- |
| 1587 |
// Allow seeded attributes to declare dependencies. |
--- |
1587 |
// Allow seeded attributes to declare dependencies. |
--- |
| 1588 |
// Remember the seeding state. |
--- |
1588 |
// Remember the seeding state. |
--- |
| 1589 |
if (UpdateAfterInit) { |
0 |
1589 |
if (UpdateAfterInit) { |
0 |
| 1590 |
AttributorPhase OldPhase = Phase; |
0 |
1590 |
AttributorPhase OldPhase = Phase; |
0 |
| 1591 |
Phase = AttributorPhase::UPDATE; |
0 |
1591 |
Phase = AttributorPhase::UPDATE; |
0 |
| 1592 |
|
--- |
1592 |
|
--- |
| 1593 |
updateAA(AA); |
0 |
1593 |
updateAA(AA); |
0 |
| 1594 |
|
--- |
1594 |
|
--- |
| 1595 |
Phase = OldPhase; |
0 |
1595 |
Phase = OldPhase; |
0 |
| 1596 |
} |
--- |
1596 |
} |
--- |
| 1597 |
|
--- |
1597 |
|
--- |
| 1598 |
if (QueryingAA && AA.getState().isValidState()) |
0 |
1598 |
if (QueryingAA && AA.getState().isValidState()) |
0 |
| 1599 |
recordDependence(AA, const_cast(*QueryingAA), |
0 |
1599 |
recordDependence(AA, const_cast(*QueryingAA), |
0 |
| 1600 |
DepClass); |
--- |
1600 |
DepClass); |
--- |
| 1601 |
return &AA; |
0 |
1601 |
return &AA; |
0 |
| 1602 |
} |
--- |
1602 |
} |
--- |
| 1603 |
|
--- |
1603 |
|
--- |
| 1604 |
template |
--- |
1604 |
template |
--- |
| 1605 |
const AAType *getOrCreateAAFor(const IRPosition &IRP) { |
0 |
1605 |
const AAType *getOrCreateAAFor(const IRPosition &IRP) { |
0 |
| 1606 |
return getOrCreateAAFor(IRP, /* QueryingAA */ nullptr, |
0 |
1606 |
return getOrCreateAAFor(IRP, /* QueryingAA */ nullptr, |
0 |
| 1607 |
DepClassTy::NONE); |
0 |
1607 |
DepClassTy::NONE); |
0 |
| 1608 |
} |
--- |
1608 |
} |
--- |
| 1609 |
|
--- |
1609 |
|
--- |
| 1610 |
/// Return the attribute of \p AAType for \p IRP if existing and valid. This |
--- |
1610 |
/// Return the attribute of \p AAType for \p IRP if existing and valid. This |
--- |
| 1611 |
/// also allows non-AA users lookup. |
--- |
1611 |
/// also allows non-AA users lookup. |
--- |
| 1612 |
template |
--- |
1612 |
template |
--- |
| 1613 |
AAType *lookupAAFor(const IRPosition &IRP, |
0 |
1613 |
AAType *lookupAAFor(const IRPosition &IRP, |
0 |
| 1614 |
const AbstractAttribute *QueryingAA = nullptr, |
--- |
1614 |
const AbstractAttribute *QueryingAA = nullptr, |
--- |
| 1615 |
DepClassTy DepClass = DepClassTy::OPTIONAL, |
--- |
1615 |
DepClassTy DepClass = DepClassTy::OPTIONAL, |
--- |
| 1616 |
bool AllowInvalidState = false) { |
--- |
1616 |
bool AllowInvalidState = false) { |
--- |
| 1617 |
static_assert(std::is_base_of::value, |
--- |
1617 |
static_assert(std::is_base_of::value, |
--- |
| 1618 |
"Cannot query an attribute with a type not derived from " |
--- |
1618 |
"Cannot query an attribute with a type not derived from " |
--- |
| 1619 |
"'AbstractAttribute'!"); |
--- |
1619 |
"'AbstractAttribute'!"); |
--- |
| 1620 |
// Lookup the abstract attribute of type AAType. If found, return it after |
--- |
1620 |
// Lookup the abstract attribute of type AAType. If found, return it after |
--- |
| 1621 |
// registering a dependence of QueryingAA on the one returned attribute. |
--- |
1621 |
// registering a dependence of QueryingAA on the one returned attribute. |
--- |
| 1622 |
AbstractAttribute *AAPtr = AAMap.lookup({&AAType::ID, IRP}); |
0 |
1622 |
AbstractAttribute *AAPtr = AAMap.lookup({&AAType::ID, IRP}); |
0 |
| 1623 |
if (!AAPtr) |
0 |
1623 |
if (!AAPtr) |
0 |
| 1624 |
return nullptr; |
0 |
1624 |
return nullptr; |
0 |
| 1625 |
|
--- |
1625 |
|
--- |
| 1626 |
AAType *AA = static_cast(AAPtr); |
0 |
1626 |
AAType *AA = static_cast(AAPtr); |
0 |
| 1627 |
|
--- |
1627 |
|
--- |
| 1628 |
// Do not register a dependence on an attribute with an invalid state. |
--- |
1628 |
// Do not register a dependence on an attribute with an invalid state. |
--- |
| 1629 |
if (DepClass != DepClassTy::NONE && QueryingAA && |
0 |
1629 |
if (DepClass != DepClassTy::NONE && QueryingAA && |
0 |
| 1630 |
AA->getState().isValidState()) |
0 |
1630 |
AA->getState().isValidState()) |
0 |
| 1631 |
recordDependence(*AA, const_cast(*QueryingAA), |
0 |
1631 |
recordDependence(*AA, const_cast(*QueryingAA), |
0 |
| 1632 |
DepClass); |
--- |
1632 |
DepClass); |
--- |
| 1633 |
|
--- |
1633 |
|
--- |
| 1634 |
// Return nullptr if this attribute has an invalid state. |
--- |
1634 |
// Return nullptr if this attribute has an invalid state. |
--- |
| 1635 |
if (!AllowInvalidState && !AA->getState().isValidState()) |
0 |
1635 |
if (!AllowInvalidState && !AA->getState().isValidState()) |
0 |
| 1636 |
return nullptr; |
0 |
1636 |
return nullptr; |
0 |
| 1637 |
return AA; |
0 |
1637 |
return AA; |
0 |
| 1638 |
} |
--- |
1638 |
} |
--- |
| 1639 |
|
--- |
1639 |
|
--- |
| 1640 |
/// Allows a query AA to request an update if a new query was received. |
--- |
1640 |
/// Allows a query AA to request an update if a new query was received. |
--- |
| 1641 |
void registerForUpdate(AbstractAttribute &AA); |
--- |
1641 |
void registerForUpdate(AbstractAttribute &AA); |
--- |
| 1642 |
|
--- |
1642 |
|
--- |
| 1643 |
/// Explicitly record a dependence from \p FromAA to \p ToAA, that is if |
--- |
1643 |
/// Explicitly record a dependence from \p FromAA to \p ToAA, that is if |
--- |
| 1644 |
/// \p FromAA changes \p ToAA should be updated as well. |
--- |
1644 |
/// \p FromAA changes \p ToAA should be updated as well. |
--- |
| 1645 |
/// |
--- |
1645 |
/// |
--- |
| 1646 |
/// This method should be used in conjunction with the `getAAFor` method and |
--- |
1646 |
/// This method should be used in conjunction with the `getAAFor` method and |
--- |
| 1647 |
/// with the DepClass enum passed to the method set to None. This can |
--- |
1647 |
/// with the DepClass enum passed to the method set to None. This can |
--- |
| 1648 |
/// be beneficial to avoid false dependences but it requires the users of |
--- |
1648 |
/// be beneficial to avoid false dependences but it requires the users of |
--- |
| 1649 |
/// `getAAFor` to explicitly record true dependences through this method. |
--- |
1649 |
/// `getAAFor` to explicitly record true dependences through this method. |
--- |
| 1650 |
/// The \p DepClass flag indicates if the dependence is striclty necessary. |
--- |
1650 |
/// The \p DepClass flag indicates if the dependence is striclty necessary. |
--- |
| 1651 |
/// That means for required dependences, if \p FromAA changes to an invalid |
--- |
1651 |
/// That means for required dependences, if \p FromAA changes to an invalid |
--- |
| 1652 |
/// state, \p ToAA can be moved to a pessimistic fixpoint because it required |
--- |
1652 |
/// state, \p ToAA can be moved to a pessimistic fixpoint because it required |
--- |
| 1653 |
/// information from \p FromAA but none are available anymore. |
--- |
1653 |
/// information from \p FromAA but none are available anymore. |
--- |
| 1654 |
void recordDependence(const AbstractAttribute &FromAA, |
--- |
1654 |
void recordDependence(const AbstractAttribute &FromAA, |
--- |
| 1655 |
const AbstractAttribute &ToAA, DepClassTy DepClass); |
--- |
1655 |
const AbstractAttribute &ToAA, DepClassTy DepClass); |
--- |
| 1656 |
|
--- |
1656 |
|
--- |
| 1657 |
/// Introduce a new abstract attribute into the fixpoint analysis. |
--- |
1657 |
/// Introduce a new abstract attribute into the fixpoint analysis. |
--- |
| 1658 |
/// |
--- |
1658 |
/// |
--- |
| 1659 |
/// Note that ownership of the attribute is given to the Attributor. It will |
--- |
1659 |
/// Note that ownership of the attribute is given to the Attributor. It will |
--- |
| 1660 |
/// invoke delete for the Attributor on destruction of the Attributor. |
--- |
1660 |
/// invoke delete for the Attributor on destruction of the Attributor. |
--- |
| 1661 |
/// |
--- |
1661 |
/// |
--- |
| 1662 |
/// Attributes are identified by their IR position (AAType::getIRPosition()) |
--- |
1662 |
/// Attributes are identified by their IR position (AAType::getIRPosition()) |
--- |
| 1663 |
/// and the address of their static member (see AAType::ID). |
--- |
1663 |
/// and the address of their static member (see AAType::ID). |
--- |
| 1664 |
template AAType ®isterAA(AAType &AA) { |
0 |
1664 |
template AAType ®isterAA(AAType &AA) { |
0 |
| 1665 |
static_assert(std::is_base_of::value, |
--- |
1665 |
static_assert(std::is_base_of::value, |
--- |
| 1666 |
"Cannot register an attribute with a type not derived from " |
--- |
1666 |
"Cannot register an attribute with a type not derived from " |
--- |
| 1667 |
"'AbstractAttribute'!"); |
--- |
1667 |
"'AbstractAttribute'!"); |
--- |
| 1668 |
// Put the attribute in the lookup map structure and the container we use to |
--- |
1668 |
// Put the attribute in the lookup map structure and the container we use to |
--- |
| 1669 |
// keep track of all attributes. |
--- |
1669 |
// keep track of all attributes. |
--- |
| 1670 |
const IRPosition &IRP = AA.getIRPosition(); |
0 |
1670 |
const IRPosition &IRP = AA.getIRPosition(); |
0 |
| 1671 |
AbstractAttribute *&AAPtr = AAMap[{&AAType::ID, IRP}]; |
0 |
1671 |
AbstractAttribute *&AAPtr = AAMap[{&AAType::ID, IRP}]; |
0 |
| 1672 |
|
--- |
1672 |
|
--- |
| 1673 |
assert(!AAPtr && "Attribute already in map!"); |
0 |
1673 |
assert(!AAPtr && "Attribute already in map!"); |
0 |
| 1674 |
AAPtr = &AA; |
0 |
1674 |
AAPtr = &AA; |
0 |
| 1675 |
|
--- |
1675 |
|
--- |
| 1676 |
// Register AA with the synthetic root only before the manifest stage. |
--- |
1676 |
// Register AA with the synthetic root only before the manifest stage. |
--- |
| 1677 |
if (Phase == AttributorPhase::SEEDING || Phase == AttributorPhase::UPDATE) |
0 |
1677 |
if (Phase == AttributorPhase::SEEDING || Phase == AttributorPhase::UPDATE) |
0 |
| 1678 |
DG.SyntheticRoot.Deps.insert( |
0 |
1678 |
DG.SyntheticRoot.Deps.insert( |
0 |
| 1679 |
AADepGraphNode::DepTy(&AA, unsigned(DepClassTy::REQUIRED))); |
0 |
1679 |
AADepGraphNode::DepTy(&AA, unsigned(DepClassTy::REQUIRED))); |
0 |
| 1680 |
|
--- |
1680 |
|
--- |
| 1681 |
return AA; |
0 |
1681 |
return AA; |
0 |
| 1682 |
} |
--- |
1682 |
} |
--- |
| 1683 |
|
--- |
1683 |
|
--- |
| 1684 |
/// Return the internal information cache. |
--- |
1684 |
/// Return the internal information cache. |
--- |
| 1685 |
InformationCache &getInfoCache() { return InfoCache; } |
0 |
1685 |
InformationCache &getInfoCache() { return InfoCache; } |
0 |
| 1686 |
|
--- |
1686 |
|
--- |
| 1687 |
/// Return true if this is a module pass, false otherwise. |
--- |
1687 |
/// Return true if this is a module pass, false otherwise. |
--- |
| 1688 |
bool isModulePass() const { return Configuration.IsModulePass; } |
0 |
1688 |
bool isModulePass() const { return Configuration.IsModulePass; } |
0 |
| 1689 |
|
--- |
1689 |
|
--- |
| 1690 |
/// Return true if we derive attributes for \p Fn |
--- |
1690 |
/// Return true if we derive attributes for \p Fn |
--- |
| 1691 |
bool isRunOn(Function &Fn) const { return isRunOn(&Fn); } |
0 |
1691 |
bool isRunOn(Function &Fn) const { return isRunOn(&Fn); } |
0 |
| 1692 |
bool isRunOn(Function *Fn) const { |
0 |
1692 |
bool isRunOn(Function *Fn) const { |
0 |
| 1693 |
return Functions.empty() || Functions.count(Fn); |
0 |
1693 |
return Functions.empty() || Functions.count(Fn); |
0 |
| 1694 |
} |
--- |
1694 |
} |
--- |
| 1695 |
|
--- |
1695 |
|
--- |
| 1696 |
template bool shouldUpdateAA(const IRPosition &IRP) { |
0 |
1696 |
template bool shouldUpdateAA(const IRPosition &IRP) { |
0 |
| 1697 |
// If this is queried in the manifest stage, we force the AA to indicate |
--- |
1697 |
// If this is queried in the manifest stage, we force the AA to indicate |
--- |
| 1698 |
// pessimistic fixpoint immediately. |
--- |
1698 |
// pessimistic fixpoint immediately. |
--- |
| 1699 |
if (Phase == AttributorPhase::MANIFEST || Phase == AttributorPhase::CLEANUP) |
0 |
1699 |
if (Phase == AttributorPhase::MANIFEST || Phase == AttributorPhase::CLEANUP) |
0 |
| 1700 |
return false; |
0 |
1700 |
return false; |
0 |
| 1701 |
|
--- |
1701 |
|
--- |
| 1702 |
Function *AssociatedFn = IRP.getAssociatedFunction(); |
0 |
1702 |
Function *AssociatedFn = IRP.getAssociatedFunction(); |
0 |
| 1703 |
|
--- |
1703 |
|
--- |
| 1704 |
// Check if we require a callee but there is none. |
--- |
1704 |
// Check if we require a callee but there is none. |
--- |
| 1705 |
if (!AssociatedFn && AAType::requiresCalleeForCallBase() && |
0 |
1705 |
if (!AssociatedFn && AAType::requiresCalleeForCallBase() && |
0 |
| 1706 |
IRP.isAnyCallSitePosition()) |
0 |
1706 |
IRP.isAnyCallSitePosition()) |
0 |
| 1707 |
return false; |
0 |
1707 |
return false; |
0 |
| 1708 |
|
--- |
1708 |
|
--- |
| 1709 |
// Check if we require a calles but we can't see all. |
--- |
1709 |
// Check if we require a calles but we can't see all. |
--- |
| 1710 |
if (AAType::requiresCallersForArgOrFunction()) |
0 |
1710 |
if (AAType::requiresCallersForArgOrFunction()) |
0 |
| 1711 |
if (IRP.getPositionKind() == IRPosition::IRP_FUNCTION || |
0 |
1711 |
if (IRP.getPositionKind() == IRPosition::IRP_FUNCTION || |
0 |
| 1712 |
IRP.getPositionKind() == IRPosition::IRP_ARGUMENT) |
0 |
1712 |
IRP.getPositionKind() == IRPosition::IRP_ARGUMENT) |
0 |
| 1713 |
if (!AssociatedFn->hasLocalLinkage()) |
0 |
1713 |
if (!AssociatedFn->hasLocalLinkage()) |
0 |
| 1714 |
return false; |
0 |
1714 |
return false; |
0 |
| 1715 |
|
--- |
1715 |
|
--- |
| 1716 |
if (!AAType::isValidIRPositionForUpdate(*this, IRP)) |
0 |
1716 |
if (!AAType::isValidIRPositionForUpdate(*this, IRP)) |
0 |
| 1717 |
return false; |
0 |
1717 |
return false; |
0 |
| 1718 |
|
--- |
1718 |
|
--- |
| 1719 |
// We update only AAs associated with functions in the Functions set or |
--- |
1719 |
// We update only AAs associated with functions in the Functions set or |
--- |
| 1720 |
// call sites of them. |
--- |
1720 |
// call sites of them. |
--- |
| 1721 |
return (!AssociatedFn || isModulePass() || isRunOn(AssociatedFn) || |
0 |
1721 |
return (!AssociatedFn || isModulePass() || isRunOn(AssociatedFn) || |
0 |
| 1722 |
isRunOn(IRP.getAnchorScope())); |
0 |
1722 |
isRunOn(IRP.getAnchorScope())); |
0 |
| 1723 |
} |
--- |
1723 |
} |
--- |
| 1724 |
|
--- |
1724 |
|
--- |
| 1725 |
template |
--- |
1725 |
template |
--- |
| 1726 |
bool shouldInitialize(const IRPosition &IRP, bool &ShouldUpdateAA) { |
0 |
1726 |
bool shouldInitialize(const IRPosition &IRP, bool &ShouldUpdateAA) { |
0 |
| 1727 |
if (!AAType::isValidIRPositionForInit(*this, IRP)) |
0 |
1727 |
if (!AAType::isValidIRPositionForInit(*this, IRP)) |
0 |
| 1728 |
return false; |
0 |
1728 |
return false; |
0 |
| 1729 |
|
--- |
1729 |
|
--- |
| 1730 |
if (Configuration.Allowed && !Configuration.Allowed->count(&AAType::ID)) |
0 |
1730 |
if (Configuration.Allowed && !Configuration.Allowed->count(&AAType::ID)) |
0 |
| 1731 |
return false; |
0 |
1731 |
return false; |
0 |
| 1732 |
|
--- |
1732 |
|
--- |
| 1733 |
// For now we skip anything in naked and optnone functions. |
--- |
1733 |
// For now we skip anything in naked and optnone functions. |
--- |
| 1734 |
const Function *AnchorFn = IRP.getAnchorScope(); |
0 |
1734 |
const Function *AnchorFn = IRP.getAnchorScope(); |
0 |
| 1735 |
if (AnchorFn && (AnchorFn->hasFnAttribute(Attribute::Naked) || |
0 |
1735 |
if (AnchorFn && (AnchorFn->hasFnAttribute(Attribute::Naked) || |
0 |
| 1736 |
AnchorFn->hasFnAttribute(Attribute::OptimizeNone))) |
0 |
1736 |
AnchorFn->hasFnAttribute(Attribute::OptimizeNone))) |
0 |
| 1737 |
return false; |
0 |
1737 |
return false; |
0 |
| 1738 |
|
--- |
1738 |
|
--- |
| 1739 |
// Avoid too many nested initializations to prevent a stack overflow. |
--- |
1739 |
// Avoid too many nested initializations to prevent a stack overflow. |
--- |
| 1740 |
if (InitializationChainLength > MaxInitializationChainLength) |
0 |
1740 |
if (InitializationChainLength > MaxInitializationChainLength) |
0 |
| 1741 |
return false; |
0 |
1741 |
return false; |
0 |
| 1742 |
|
--- |
1742 |
|
--- |
| 1743 |
ShouldUpdateAA = shouldUpdateAA(IRP); |
0 |
1743 |
ShouldUpdateAA = shouldUpdateAA(IRP); |
0 |
| 1744 |
|
--- |
1744 |
|
--- |
| 1745 |
return !AAType::hasTrivialInitializer() || ShouldUpdateAA; |
0 |
1745 |
return !AAType::hasTrivialInitializer() || ShouldUpdateAA; |
0 |
| 1746 |
} |
--- |
1746 |
} |
--- |
| 1747 |
|
--- |
1747 |
|
--- |
| 1748 |
/// Determine opportunities to derive 'default' attributes in \p F and create |
--- |
1748 |
/// Determine opportunities to derive 'default' attributes in \p F and create |
--- |
| 1749 |
/// abstract attribute objects for them. |
--- |
1749 |
/// abstract attribute objects for them. |
--- |
| 1750 |
/// |
--- |
1750 |
/// |
--- |
| 1751 |
/// \param F The function that is checked for attribute opportunities. |
--- |
1751 |
/// \param F The function that is checked for attribute opportunities. |
--- |
| 1752 |
/// |
--- |
1752 |
/// |
--- |
| 1753 |
/// Note that abstract attribute instances are generally created even if the |
--- |
1753 |
/// Note that abstract attribute instances are generally created even if the |
--- |
| 1754 |
/// IR already contains the information they would deduce. The most important |
--- |
1754 |
/// IR already contains the information they would deduce. The most important |
--- |
| 1755 |
/// reason for this is the single interface, the one of the abstract attribute |
--- |
1755 |
/// reason for this is the single interface, the one of the abstract attribute |
--- |
| 1756 |
/// instance, which can be queried without the need to look at the IR in |
--- |
1756 |
/// instance, which can be queried without the need to look at the IR in |
--- |
| 1757 |
/// various places. |
--- |
1757 |
/// various places. |
--- |
| 1758 |
void identifyDefaultAbstractAttributes(Function &F); |
--- |
1758 |
void identifyDefaultAbstractAttributes(Function &F); |
--- |
| 1759 |
|
--- |
1759 |
|
--- |
| 1760 |
/// Determine whether the function \p F is IPO amendable |
--- |
1760 |
/// Determine whether the function \p F is IPO amendable |
--- |
| 1761 |
/// |
--- |
1761 |
/// |
--- |
| 1762 |
/// If a function is exactly defined or it has alwaysinline attribute |
--- |
1762 |
/// If a function is exactly defined or it has alwaysinline attribute |
--- |
| 1763 |
/// and is viable to be inlined, we say it is IPO amendable |
--- |
1763 |
/// and is viable to be inlined, we say it is IPO amendable |
--- |
| 1764 |
bool isFunctionIPOAmendable(const Function &F) { |
0 |
1764 |
bool isFunctionIPOAmendable(const Function &F) { |
0 |
| 1765 |
return F.hasExactDefinition() || InfoCache.InlineableFunctions.count(&F) || |
0 |
1765 |
return F.hasExactDefinition() || InfoCache.InlineableFunctions.count(&F) || |
0 |
| 1766 |
(Configuration.IPOAmendableCB && Configuration.IPOAmendableCB(F)); |
0 |
1766 |
(Configuration.IPOAmendableCB && Configuration.IPOAmendableCB(F)); |
0 |
| 1767 |
} |
--- |
1767 |
} |
--- |
| 1768 |
|
--- |
1768 |
|
--- |
| 1769 |
/// Mark the internal function \p F as live. |
--- |
1769 |
/// Mark the internal function \p F as live. |
--- |
| 1770 |
/// |
--- |
1770 |
/// |
--- |
| 1771 |
/// This will trigger the identification and initialization of attributes for |
--- |
1771 |
/// This will trigger the identification and initialization of attributes for |
--- |
| 1772 |
/// \p F. |
--- |
1772 |
/// \p F. |
--- |
| 1773 |
void markLiveInternalFunction(const Function &F) { |
--- |
1773 |
void markLiveInternalFunction(const Function &F) { |
--- |
| 1774 |
assert(F.hasLocalLinkage() && |
--- |
1774 |
assert(F.hasLocalLinkage() && |
--- |
| 1775 |
"Only local linkage is assumed dead initially."); |
--- |
1775 |
"Only local linkage is assumed dead initially."); |
--- |
| 1776 |
|
--- |
1776 |
|
--- |
| 1777 |
if (Configuration.DefaultInitializeLiveInternals) |
--- |
1777 |
if (Configuration.DefaultInitializeLiveInternals) |
--- |
| 1778 |
identifyDefaultAbstractAttributes(const_cast(F)); |
--- |
1778 |
identifyDefaultAbstractAttributes(const_cast(F)); |
--- |
| 1779 |
if (Configuration.InitializationCallback) |
--- |
1779 |
if (Configuration.InitializationCallback) |
--- |
| 1780 |
Configuration.InitializationCallback(*this, F); |
--- |
1780 |
Configuration.InitializationCallback(*this, F); |
--- |
| 1781 |
} |
--- |
1781 |
} |
--- |
| 1782 |
|
--- |
1782 |
|
--- |
| 1783 |
/// Helper function to remove callsite. |
--- |
1783 |
/// Helper function to remove callsite. |
--- |
| 1784 |
void removeCallSite(CallInst *CI) { |
--- |
1784 |
void removeCallSite(CallInst *CI) { |
--- |
| 1785 |
if (!CI) |
--- |
1785 |
if (!CI) |
--- |
| 1786 |
return; |
--- |
1786 |
return; |
--- |
| 1787 |
|
--- |
1787 |
|
--- |
| 1788 |
Configuration.CGUpdater.removeCallSite(*CI); |
--- |
1788 |
Configuration.CGUpdater.removeCallSite(*CI); |
--- |
| 1789 |
} |
--- |
1789 |
} |
--- |
| 1790 |
|
--- |
1790 |
|
--- |
| 1791 |
/// Record that \p U is to be replaces with \p NV after information was |
--- |
1791 |
/// Record that \p U is to be replaces with \p NV after information was |
--- |
| 1792 |
/// manifested. This also triggers deletion of trivially dead istructions. |
--- |
1792 |
/// manifested. This also triggers deletion of trivially dead istructions. |
--- |
| 1793 |
bool changeUseAfterManifest(Use &U, Value &NV) { |
--- |
1793 |
bool changeUseAfterManifest(Use &U, Value &NV) { |
--- |
| 1794 |
Value *&V = ToBeChangedUses[&U]; |
--- |
1794 |
Value *&V = ToBeChangedUses[&U]; |
--- |
| 1795 |
if (V && (V->stripPointerCasts() == NV.stripPointerCasts() || |
--- |
1795 |
if (V && (V->stripPointerCasts() == NV.stripPointerCasts() || |
--- |
| 1796 |
isa_and_nonnull(V))) |
--- |
1796 |
isa_and_nonnull(V))) |
--- |
| 1797 |
return false; |
--- |
1797 |
return false; |
--- |
| 1798 |
assert((!V || V == &NV || isa(NV)) && |
--- |
1798 |
assert((!V || V == &NV || isa(NV)) && |
--- |
| 1799 |
"Use was registered twice for replacement with different values!"); |
--- |
1799 |
"Use was registered twice for replacement with different values!"); |
--- |
| 1800 |
V = &NV; |
--- |
1800 |
V = &NV; |
--- |
| 1801 |
return true; |
--- |
1801 |
return true; |
--- |
| 1802 |
} |
--- |
1802 |
} |
--- |
| 1803 |
|
--- |
1803 |
|
--- |
| 1804 |
/// Helper function to replace all uses associated with \p IRP with \p NV. |
--- |
1804 |
/// Helper function to replace all uses associated with \p IRP with \p NV. |
--- |
| 1805 |
/// Return true if there is any change. The flag \p ChangeDroppable indicates |
--- |
1805 |
/// Return true if there is any change. The flag \p ChangeDroppable indicates |
--- |
| 1806 |
/// if dropppable uses should be changed too. |
--- |
1806 |
/// if dropppable uses should be changed too. |
--- |
| 1807 |
bool changeAfterManifest(const IRPosition IRP, Value &NV, |
--- |
1807 |
bool changeAfterManifest(const IRPosition IRP, Value &NV, |
--- |
| 1808 |
bool ChangeDroppable = true) { |
--- |
1808 |
bool ChangeDroppable = true) { |
--- |
| 1809 |
if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE_ARGUMENT) { |
--- |
1809 |
if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE_ARGUMENT) { |
--- |
| 1810 |
auto *CB = cast(IRP.getCtxI()); |
--- |
1810 |
auto *CB = cast(IRP.getCtxI()); |
--- |
| 1811 |
return changeUseAfterManifest( |
--- |
1811 |
return changeUseAfterManifest( |
--- |
| 1812 |
CB->getArgOperandUse(IRP.getCallSiteArgNo()), NV); |
--- |
1812 |
CB->getArgOperandUse(IRP.getCallSiteArgNo()), NV); |
--- |
| 1813 |
} |
--- |
1813 |
} |
--- |
| 1814 |
Value &V = IRP.getAssociatedValue(); |
--- |
1814 |
Value &V = IRP.getAssociatedValue(); |
--- |
| 1815 |
auto &Entry = ToBeChangedValues[&V]; |
--- |
1815 |
auto &Entry = ToBeChangedValues[&V]; |
--- |
| 1816 |
Value *CurNV = get<0>(Entry); |
--- |
1816 |
Value *CurNV = get<0>(Entry); |
--- |
| 1817 |
if (CurNV && (CurNV->stripPointerCasts() == NV.stripPointerCasts() || |
--- |
1817 |
if (CurNV && (CurNV->stripPointerCasts() == NV.stripPointerCasts() || |
--- |
| 1818 |
isa(CurNV))) |
--- |
1818 |
isa(CurNV))) |
--- |
| 1819 |
return false; |
--- |
1819 |
return false; |
--- |
| 1820 |
assert((!CurNV || CurNV == &NV || isa(NV)) && |
--- |
1820 |
assert((!CurNV || CurNV == &NV || isa(NV)) && |
--- |
| 1821 |
"Value replacement was registered twice with different values!"); |
--- |
1821 |
"Value replacement was registered twice with different values!"); |
--- |
| 1822 |
Entry = {&NV, ChangeDroppable}; |
--- |
1822 |
Entry = {&NV, ChangeDroppable}; |
--- |
| 1823 |
return true; |
--- |
1823 |
return true; |
--- |
| 1824 |
} |
--- |
1824 |
} |
--- |
| 1825 |
|
--- |
1825 |
|
--- |
| 1826 |
/// Record that \p I is to be replaced with `unreachable` after information |
--- |
1826 |
/// Record that \p I is to be replaced with `unreachable` after information |
--- |
| 1827 |
/// was manifested. |
--- |
1827 |
/// was manifested. |
--- |
| 1828 |
void changeToUnreachableAfterManifest(Instruction *I) { |
--- |
1828 |
void changeToUnreachableAfterManifest(Instruction *I) { |
--- |
| 1829 |
ToBeChangedToUnreachableInsts.insert(I); |
--- |
1829 |
ToBeChangedToUnreachableInsts.insert(I); |
--- |
| 1830 |
} |
--- |
1830 |
} |
--- |
| 1831 |
|
--- |
1831 |
|
--- |
| 1832 |
/// Record that \p II has at least one dead successor block. This information |
--- |
1832 |
/// Record that \p II has at least one dead successor block. This information |
--- |
| 1833 |
/// is used, e.g., to replace \p II with a call, after information was |
--- |
1833 |
/// is used, e.g., to replace \p II with a call, after information was |
--- |
| 1834 |
/// manifested. |
--- |
1834 |
/// manifested. |
--- |
| 1835 |
void registerInvokeWithDeadSuccessor(InvokeInst &II) { |
--- |
1835 |
void registerInvokeWithDeadSuccessor(InvokeInst &II) { |
--- |
| 1836 |
InvokeWithDeadSuccessor.insert(&II); |
--- |
1836 |
InvokeWithDeadSuccessor.insert(&II); |
--- |
| 1837 |
} |
--- |
1837 |
} |
--- |
| 1838 |
|
--- |
1838 |
|
--- |
| 1839 |
/// Record that \p I is deleted after information was manifested. This also |
--- |
1839 |
/// Record that \p I is deleted after information was manifested. This also |
--- |
| 1840 |
/// triggers deletion of trivially dead istructions. |
--- |
1840 |
/// triggers deletion of trivially dead istructions. |
--- |
| 1841 |
void deleteAfterManifest(Instruction &I) { ToBeDeletedInsts.insert(&I); } |
--- |
1841 |
void deleteAfterManifest(Instruction &I) { ToBeDeletedInsts.insert(&I); } |
--- |
| 1842 |
|
--- |
1842 |
|
--- |
| 1843 |
/// Record that \p BB is deleted after information was manifested. This also |
--- |
1843 |
/// Record that \p BB is deleted after information was manifested. This also |
--- |
| 1844 |
/// triggers deletion of trivially dead istructions. |
--- |
1844 |
/// triggers deletion of trivially dead istructions. |
--- |
| 1845 |
void deleteAfterManifest(BasicBlock &BB) { ToBeDeletedBlocks.insert(&BB); } |
--- |
1845 |
void deleteAfterManifest(BasicBlock &BB) { ToBeDeletedBlocks.insert(&BB); } |
--- |
| 1846 |
|
--- |
1846 |
|
--- |
| 1847 |
// Record that \p BB is added during the manifest of an AA. Added basic blocks |
--- |
1847 |
// Record that \p BB is added during the manifest of an AA. Added basic blocks |
--- |
| 1848 |
// are preserved in the IR. |
--- |
1848 |
// are preserved in the IR. |
--- |
| 1849 |
void registerManifestAddedBasicBlock(BasicBlock &BB) { |
--- |
1849 |
void registerManifestAddedBasicBlock(BasicBlock &BB) { |
--- |
| 1850 |
ManifestAddedBlocks.insert(&BB); |
--- |
1850 |
ManifestAddedBlocks.insert(&BB); |
--- |
| 1851 |
} |
--- |
1851 |
} |
--- |
| 1852 |
|
--- |
1852 |
|
--- |
| 1853 |
/// Record that \p F is deleted after information was manifested. |
--- |
1853 |
/// Record that \p F is deleted after information was manifested. |
--- |
| 1854 |
void deleteAfterManifest(Function &F) { |
--- |
1854 |
void deleteAfterManifest(Function &F) { |
--- |
| 1855 |
if (Configuration.DeleteFns) |
--- |
1855 |
if (Configuration.DeleteFns) |
--- |
| 1856 |
ToBeDeletedFunctions.insert(&F); |
--- |
1856 |
ToBeDeletedFunctions.insert(&F); |
--- |
| 1857 |
} |
--- |
1857 |
} |
--- |
| 1858 |
|
--- |
1858 |
|
--- |
| 1859 |
/// Return the attributes of kind \p AK existing in the IR as operand bundles |
--- |
1859 |
/// Return the attributes of kind \p AK existing in the IR as operand bundles |
--- |
| 1860 |
/// of an llvm.assume. |
--- |
1860 |
/// of an llvm.assume. |
--- |
| 1861 |
bool getAttrsFromAssumes(const IRPosition &IRP, Attribute::AttrKind AK, |
--- |
1861 |
bool getAttrsFromAssumes(const IRPosition &IRP, Attribute::AttrKind AK, |
--- |
| 1862 |
SmallVectorImpl &Attrs); |
--- |
1862 |
SmallVectorImpl &Attrs); |
--- |
| 1863 |
|
--- |
1863 |
|
--- |
| 1864 |
/// Return true if any kind in \p AKs existing in the IR at a position that |
--- |
1864 |
/// Return true if any kind in \p AKs existing in the IR at a position that |
--- |
| 1865 |
/// will affect this one. See also getAttrs(...). |
--- |
1865 |
/// will affect this one. See also getAttrs(...). |
--- |
| 1866 |
/// \param IgnoreSubsumingPositions Flag to determine if subsuming positions, |
--- |
1866 |
/// \param IgnoreSubsumingPositions Flag to determine if subsuming positions, |
--- |
| 1867 |
/// e.g., the function position if this is an |
--- |
1867 |
/// e.g., the function position if this is an |
--- |
| 1868 |
/// argument position, should be ignored. |
--- |
1868 |
/// argument position, should be ignored. |
--- |
| 1869 |
bool hasAttr(const IRPosition &IRP, ArrayRef AKs, |
--- |
1869 |
bool hasAttr(const IRPosition &IRP, ArrayRef AKs, |
--- |
| 1870 |
bool IgnoreSubsumingPositions = false, |
--- |
1870 |
bool IgnoreSubsumingPositions = false, |
--- |
| 1871 |
Attribute::AttrKind ImpliedAttributeKind = Attribute::None); |
--- |
1871 |
Attribute::AttrKind ImpliedAttributeKind = Attribute::None); |
--- |
| 1872 |
|
--- |
1872 |
|
--- |
| 1873 |
/// Return the attributes of any kind in \p AKs existing in the IR at a |
--- |
1873 |
/// Return the attributes of any kind in \p AKs existing in the IR at a |
--- |
| 1874 |
/// position that will affect this one. While each position can only have a |
--- |
1874 |
/// position that will affect this one. While each position can only have a |
--- |
| 1875 |
/// single attribute of any kind in \p AKs, there are "subsuming" positions |
--- |
1875 |
/// single attribute of any kind in \p AKs, there are "subsuming" positions |
--- |
| 1876 |
/// that could have an attribute as well. This method returns all attributes |
--- |
1876 |
/// that could have an attribute as well. This method returns all attributes |
--- |
| 1877 |
/// found in \p Attrs. |
--- |
1877 |
/// found in \p Attrs. |
--- |
| 1878 |
/// \param IgnoreSubsumingPositions Flag to determine if subsuming positions, |
--- |
1878 |
/// \param IgnoreSubsumingPositions Flag to determine if subsuming positions, |
--- |
| 1879 |
/// e.g., the function position if this is an |
--- |
1879 |
/// e.g., the function position if this is an |
--- |
| 1880 |
/// argument position, should be ignored. |
--- |
1880 |
/// argument position, should be ignored. |
--- |
| 1881 |
void getAttrs(const IRPosition &IRP, ArrayRef AKs, |
--- |
1881 |
void getAttrs(const IRPosition &IRP, ArrayRef AKs, |
--- |
| 1882 |
SmallVectorImpl &Attrs, |
--- |
1882 |
SmallVectorImpl &Attrs, |
--- |
| 1883 |
bool IgnoreSubsumingPositions = false); |
--- |
1883 |
bool IgnoreSubsumingPositions = false); |
--- |
| 1884 |
|
--- |
1884 |
|
--- |
| 1885 |
/// Remove all \p AttrKinds attached to \p IRP. |
--- |
1885 |
/// Remove all \p AttrKinds attached to \p IRP. |
--- |
| 1886 |
ChangeStatus removeAttrs(const IRPosition &IRP, |
--- |
1886 |
ChangeStatus removeAttrs(const IRPosition &IRP, |
--- |
| 1887 |
const ArrayRef &AttrKinds); |
--- |
1887 |
const ArrayRef &AttrKinds); |
--- |
| 1888 |
|
--- |
1888 |
|
--- |
| 1889 |
/// Attach \p DeducedAttrs to \p IRP, if \p ForceReplace is set we do this |
--- |
1889 |
/// Attach \p DeducedAttrs to \p IRP, if \p ForceReplace is set we do this |
--- |
| 1890 |
/// even if the same attribute kind was already present. |
--- |
1890 |
/// even if the same attribute kind was already present. |
--- |
| 1891 |
ChangeStatus manifestAttrs(const IRPosition &IRP, |
--- |
1891 |
ChangeStatus manifestAttrs(const IRPosition &IRP, |
--- |
| 1892 |
const ArrayRef &DeducedAttrs, |
--- |
1892 |
const ArrayRef &DeducedAttrs, |
--- |
| 1893 |
bool ForceReplace = false); |
--- |
1893 |
bool ForceReplace = false); |
--- |
| 1894 |
|
--- |
1894 |
|
--- |
| 1895 |
private: |
--- |
1895 |
private: |
--- |
| 1896 |
/// Helper to check \p Attrs for \p AK, if not found, check if \p |
--- |
1896 |
/// Helper to check \p Attrs for \p AK, if not found, check if \p |
--- |
| 1897 |
/// AAType::isImpliedByIR is true, and if not, create AAType for \p IRP. |
--- |
1897 |
/// AAType::isImpliedByIR is true, and if not, create AAType for \p IRP. |
--- |
| 1898 |
template |
--- |
1898 |
template |
--- |
| 1899 |
void checkAndQueryIRAttr(const IRPosition &IRP, AttributeSet Attrs); |
--- |
1899 |
void checkAndQueryIRAttr(const IRPosition &IRP, AttributeSet Attrs); |
--- |
| 1900 |
|
--- |
1900 |
|
--- |
| 1901 |
/// Helper to apply \p CB on all attributes of type \p AttrDescs of \p IRP. |
--- |
1901 |
/// Helper to apply \p CB on all attributes of type \p AttrDescs of \p IRP. |
--- |
| 1902 |
template |
--- |
1902 |
template |
--- |
| 1903 |
ChangeStatus updateAttrMap(const IRPosition &IRP, |
--- |
1903 |
ChangeStatus updateAttrMap(const IRPosition &IRP, |
--- |
| 1904 |
const ArrayRef &AttrDescs, |
--- |
1904 |
const ArrayRef &AttrDescs, |
--- |
| 1905 |
function_ref
| --- |
1905 |
function_ref
| --- |
| |
| 1906 |
AttributeMask &, AttrBuilder &)> |
--- |
1906 |
AttributeMask &, AttrBuilder &)> |
--- |
| 1907 |
CB); |
--- |
1907 |
CB); |
--- |
| 1908 |
|
--- |
1908 |
|
--- |
| 1909 |
/// Mapping from functions/call sites to their attributes. |
--- |
1909 |
/// Mapping from functions/call sites to their attributes. |
--- |
| 1910 |
DenseMap AttrsMap; |
--- |
1910 |
DenseMap AttrsMap; |
--- |
| 1911 |
|
--- |
1911 |
|
--- |
| 1912 |
public: |
--- |
1912 |
public: |
--- |
| 1913 |
/// If \p IRP is assumed to be a constant, return it, if it is unclear yet, |
--- |
1913 |
/// If \p IRP is assumed to be a constant, return it, if it is unclear yet, |
--- |
| 1914 |
/// return std::nullopt, otherwise return `nullptr`. |
--- |
1914 |
/// return std::nullopt, otherwise return `nullptr`. |
--- |
| 1915 |
std::optional getAssumedConstant(const IRPosition &IRP, |
--- |
1915 |
std::optional getAssumedConstant(const IRPosition &IRP, |
--- |
| 1916 |
const AbstractAttribute &AA, |
--- |
1916 |
const AbstractAttribute &AA, |
--- |
| 1917 |
bool &UsedAssumedInformation); |
--- |
1917 |
bool &UsedAssumedInformation); |
--- |
| 1918 |
std::optional getAssumedConstant(const Value &V, |
--- |
1918 |
std::optional getAssumedConstant(const Value &V, |
--- |
| 1919 |
const AbstractAttribute &AA, |
--- |
1919 |
const AbstractAttribute &AA, |
--- |
| 1920 |
bool &UsedAssumedInformation) { |
--- |
1920 |
bool &UsedAssumedInformation) { |
--- |
| 1921 |
return getAssumedConstant(IRPosition::value(V), AA, UsedAssumedInformation); |
--- |
1921 |
return getAssumedConstant(IRPosition::value(V), AA, UsedAssumedInformation); |
--- |
| 1922 |
} |
--- |
1922 |
} |
--- |
| 1923 |
|
--- |
1923 |
|
--- |
| 1924 |
/// If \p V is assumed simplified, return it, if it is unclear yet, |
--- |
1924 |
/// If \p V is assumed simplified, return it, if it is unclear yet, |
--- |
| 1925 |
/// return std::nullopt, otherwise return `nullptr`. |
--- |
1925 |
/// return std::nullopt, otherwise return `nullptr`. |
--- |
| 1926 |
std::optional getAssumedSimplified(const IRPosition &IRP, |
0 |
1926 |
std::optional getAssumedSimplified(const IRPosition &IRP, |
0 |
| 1927 |
const AbstractAttribute &AA, |
--- |
1927 |
const AbstractAttribute &AA, |
--- |
| 1928 |
bool &UsedAssumedInformation, |
--- |
1928 |
bool &UsedAssumedInformation, |
--- |
| 1929 |
AA::ValueScope S) { |
--- |
1929 |
AA::ValueScope S) { |
--- |
| 1930 |
return getAssumedSimplified(IRP, &AA, UsedAssumedInformation, S); |
0 |
1930 |
return getAssumedSimplified(IRP, &AA, UsedAssumedInformation, S); |
0 |
| 1931 |
} |
--- |
1931 |
} |
--- |
| 1932 |
std::optional getAssumedSimplified(const Value &V, |
0 |
1932 |
std::optional getAssumedSimplified(const Value &V, |
0 |
| 1933 |
const AbstractAttribute &AA, |
--- |
1933 |
const AbstractAttribute &AA, |
--- |
| 1934 |
bool &UsedAssumedInformation, |
--- |
1934 |
bool &UsedAssumedInformation, |
--- |
| 1935 |
AA::ValueScope S) { |
--- |
1935 |
AA::ValueScope S) { |
--- |
| 1936 |
return getAssumedSimplified(IRPosition::value(V), AA, |
0 |
1936 |
return getAssumedSimplified(IRPosition::value(V), AA, |
0 |
| 1937 |
UsedAssumedInformation, S); |
0 |
1937 |
UsedAssumedInformation, S); |
0 |
| 1938 |
} |
--- |
1938 |
} |
--- |
| 1939 |
|
--- |
1939 |
|
--- |
| 1940 |
/// If \p V is assumed simplified, return it, if it is unclear yet, |
--- |
1940 |
/// If \p V is assumed simplified, return it, if it is unclear yet, |
--- |
| 1941 |
/// return std::nullopt, otherwise return `nullptr`. Same as the public |
--- |
1941 |
/// return std::nullopt, otherwise return `nullptr`. Same as the public |
--- |
| 1942 |
/// version except that it can be used without recording dependences on any \p |
--- |
1942 |
/// version except that it can be used without recording dependences on any \p |
--- |
| 1943 |
/// AA. |
--- |
1943 |
/// AA. |
--- |
| 1944 |
std::optional getAssumedSimplified(const IRPosition &V, |
--- |
1944 |
std::optional getAssumedSimplified(const IRPosition &V, |
--- |
| 1945 |
const AbstractAttribute *AA, |
--- |
1945 |
const AbstractAttribute *AA, |
--- |
| 1946 |
bool &UsedAssumedInformation, |
--- |
1946 |
bool &UsedAssumedInformation, |
--- |
| 1947 |
AA::ValueScope S); |
--- |
1947 |
AA::ValueScope S); |
--- |
| 1948 |
|
--- |
1948 |
|
--- |
| 1949 |
/// Try to simplify \p IRP and in the scope \p S. If successful, true is |
--- |
1949 |
/// Try to simplify \p IRP and in the scope \p S. If successful, true is |
--- |
| 1950 |
/// returned and all potential values \p IRP can take are put into \p Values. |
--- |
1950 |
/// returned and all potential values \p IRP can take are put into \p Values. |
--- |
| 1951 |
/// If the result in \p Values contains select or PHI instructions it means |
--- |
1951 |
/// If the result in \p Values contains select or PHI instructions it means |
--- |
| 1952 |
/// those could not be simplified to a single value. Recursive calls with |
--- |
1952 |
/// those could not be simplified to a single value. Recursive calls with |
--- |
| 1953 |
/// these instructions will yield their respective potential values. If false |
--- |
1953 |
/// these instructions will yield their respective potential values. If false |
--- |
| 1954 |
/// is returned no other information is valid. |
--- |
1954 |
/// is returned no other information is valid. |
--- |
| 1955 |
bool getAssumedSimplifiedValues(const IRPosition &IRP, |
--- |
1955 |
bool getAssumedSimplifiedValues(const IRPosition &IRP, |
--- |
| 1956 |
const AbstractAttribute *AA, |
--- |
1956 |
const AbstractAttribute *AA, |
--- |
| 1957 |
SmallVectorImpl &Values, |
--- |
1957 |
SmallVectorImpl &Values, |
--- |
| 1958 |
AA::ValueScope S, |
--- |
1958 |
AA::ValueScope S, |
--- |
| 1959 |
bool &UsedAssumedInformation, |
--- |
1959 |
bool &UsedAssumedInformation, |
--- |
| 1960 |
bool RecurseForSelectAndPHI = true); |
--- |
1960 |
bool RecurseForSelectAndPHI = true); |
--- |
| 1961 |
|
--- |
1961 |
|
--- |
| 1962 |
/// Register \p CB as a simplification callback. |
--- |
1962 |
/// Register \p CB as a simplification callback. |
--- |
| 1963 |
/// `Attributor::getAssumedSimplified` will use these callbacks before |
--- |
1963 |
/// `Attributor::getAssumedSimplified` will use these callbacks before |
--- |
| 1964 |
/// we it will ask `AAValueSimplify`. It is important to ensure this |
--- |
1964 |
/// we it will ask `AAValueSimplify`. It is important to ensure this |
--- |
| 1965 |
/// is called before `identifyDefaultAbstractAttributes`, assuming the |
--- |
1965 |
/// is called before `identifyDefaultAbstractAttributes`, assuming the |
--- |
| 1966 |
/// latter is called at all. |
--- |
1966 |
/// latter is called at all. |
--- |
| 1967 |
using SimplifictionCallbackTy = std::function( |
--- |
1967 |
using SimplifictionCallbackTy = std::function( |
--- |
| 1968 |
const IRPosition &, const AbstractAttribute *, bool &)>; |
--- |
1968 |
const IRPosition &, const AbstractAttribute *, bool &)>; |
--- |
| 1969 |
void registerSimplificationCallback(const IRPosition &IRP, |
--- |
1969 |
void registerSimplificationCallback(const IRPosition &IRP, |
--- |
| 1970 |
const SimplifictionCallbackTy &CB) { |
--- |
1970 |
const SimplifictionCallbackTy &CB) { |
--- |
| 1971 |
SimplificationCallbacks[IRP].emplace_back(CB); |
--- |
1971 |
SimplificationCallbacks[IRP].emplace_back(CB); |
--- |
| 1972 |
} |
--- |
1972 |
} |
--- |
| 1973 |
|
--- |
1973 |
|
--- |
| 1974 |
/// Return true if there is a simplification callback for \p IRP. |
--- |
1974 |
/// Return true if there is a simplification callback for \p IRP. |
--- |
| 1975 |
bool hasSimplificationCallback(const IRPosition &IRP) { |
--- |
1975 |
bool hasSimplificationCallback(const IRPosition &IRP) { |
--- |
| 1976 |
return SimplificationCallbacks.count(IRP); |
--- |
1976 |
return SimplificationCallbacks.count(IRP); |
--- |
| 1977 |
} |
--- |
1977 |
} |
--- |
| 1978 |
|
--- |
1978 |
|
--- |
| 1979 |
/// Register \p CB as a simplification callback. |
--- |
1979 |
/// Register \p CB as a simplification callback. |
--- |
| 1980 |
/// Similar to \p registerSimplificationCallback, the call back will be called |
--- |
1980 |
/// Similar to \p registerSimplificationCallback, the call back will be called |
--- |
| 1981 |
/// first when we simplify a global variable \p GV. |
--- |
1981 |
/// first when we simplify a global variable \p GV. |
--- |
| 1982 |
using GlobalVariableSimplifictionCallbackTy = |
--- |
1982 |
using GlobalVariableSimplifictionCallbackTy = |
--- |
| 1983 |
std::function( |
--- |
1983 |
std::function( |
--- |
| 1984 |
const GlobalVariable &, const AbstractAttribute *, bool &)>; |
--- |
1984 |
const GlobalVariable &, const AbstractAttribute *, bool &)>; |
--- |
| 1985 |
void registerGlobalVariableSimplificationCallback( |
--- |
1985 |
void registerGlobalVariableSimplificationCallback( |
--- |
| 1986 |
const GlobalVariable &GV, |
--- |
1986 |
const GlobalVariable &GV, |
--- |
| 1987 |
const GlobalVariableSimplifictionCallbackTy &CB) { |
--- |
1987 |
const GlobalVariableSimplifictionCallbackTy &CB) { |
--- |
| 1988 |
GlobalVariableSimplificationCallbacks[&GV].emplace_back(CB); |
--- |
1988 |
GlobalVariableSimplificationCallbacks[&GV].emplace_back(CB); |
--- |
| 1989 |
} |
--- |
1989 |
} |
--- |
| 1990 |
|
--- |
1990 |
|
--- |
| 1991 |
/// Return true if there is a simplification callback for \p GV. |
--- |
1991 |
/// Return true if there is a simplification callback for \p GV. |
--- |
| 1992 |
bool hasGlobalVariableSimplificationCallback(const GlobalVariable &GV) { |
0 |
1992 |
bool hasGlobalVariableSimplificationCallback(const GlobalVariable &GV) { |
0 |
| 1993 |
return GlobalVariableSimplificationCallbacks.count(&GV); |
0 |
1993 |
return GlobalVariableSimplificationCallbacks.count(&GV); |
0 |
| 1994 |
} |
--- |
1994 |
} |
--- |
| 1995 |
|
--- |
1995 |
|
--- |
| 1996 |
/// Return \p std::nullopt if there is no call back registered for \p GV or |
--- |
1996 |
/// Return \p std::nullopt if there is no call back registered for \p GV or |
--- |
| 1997 |
/// the call back is still not sure if \p GV can be simplified. Return \p |
--- |
1997 |
/// the call back is still not sure if \p GV can be simplified. Return \p |
--- |
| 1998 |
/// nullptr if \p GV can't be simplified. |
--- |
1998 |
/// nullptr if \p GV can't be simplified. |
--- |
| 1999 |
std::optional |
--- |
1999 |
std::optional |
--- |
| 2000 |
getAssumedInitializerFromCallBack(const GlobalVariable &GV, |
0 |
2000 |
getAssumedInitializerFromCallBack(const GlobalVariable &GV, |
0 |
| 2001 |
const AbstractAttribute *AA, |
--- |
2001 |
const AbstractAttribute *AA, |
--- |
| 2002 |
bool &UsedAssumedInformation) { |
--- |
2002 |
bool &UsedAssumedInformation) { |
--- |
| 2003 |
assert(GlobalVariableSimplificationCallbacks.contains(&GV)); |
0 |
2003 |
assert(GlobalVariableSimplificationCallbacks.contains(&GV)); |
0 |
| 2004 |
for (auto &CB : GlobalVariableSimplificationCallbacks.lookup(&GV)) { |
0 |
2004 |
for (auto &CB : GlobalVariableSimplificationCallbacks.lookup(&GV)) { |
0 |
| 2005 |
auto SimplifiedGV = CB(GV, AA, UsedAssumedInformation); |
0 |
2005 |
auto SimplifiedGV = CB(GV, AA, UsedAssumedInformation); |
0 |
| 2006 |
// For now we assume the call back will not return a std::nullopt. |
--- |
2006 |
// For now we assume the call back will not return a std::nullopt. |
--- |
| 2007 |
assert(SimplifiedGV.has_value() && "SimplifiedGV has not value"); |
0 |
2007 |
assert(SimplifiedGV.has_value() && "SimplifiedGV has not value"); |
0 |
| 2008 |
return *SimplifiedGV; |
0 |
2008 |
return *SimplifiedGV; |
0 |
| 2009 |
} |
0 |
2009 |
} |
0 |
| 2010 |
llvm_unreachable("there must be a callback registered"); |
0 |
2010 |
llvm_unreachable("there must be a callback registered"); |
0 |
| 2011 |
} |
--- |
2011 |
} |
--- |
| 2012 |
|
--- |
2012 |
|
--- |
| 2013 |
using VirtualUseCallbackTy = |
--- |
2013 |
using VirtualUseCallbackTy = |
--- |
| 2014 |
std::function; |
--- |
2014 |
std::function; |
--- |
| 2015 |
void registerVirtualUseCallback(const Value &V, |
--- |
2015 |
void registerVirtualUseCallback(const Value &V, |
--- |
| 2016 |
const VirtualUseCallbackTy &CB) { |
--- |
2016 |
const VirtualUseCallbackTy &CB) { |
--- |
| 2017 |
VirtualUseCallbacks[&V].emplace_back(CB); |
--- |
2017 |
VirtualUseCallbacks[&V].emplace_back(CB); |
--- |
| 2018 |
} |
--- |
2018 |
} |
--- |
| 2019 |
|
--- |
2019 |
|
--- |
| 2020 |
private: |
--- |
2020 |
private: |
--- |
| 2021 |
/// The vector with all simplification callbacks registered by outside AAs. |
--- |
2021 |
/// The vector with all simplification callbacks registered by outside AAs. |
--- |
| 2022 |
DenseMap> |
--- |
2022 |
DenseMap> |
--- |
| 2023 |
SimplificationCallbacks; |
--- |
2023 |
SimplificationCallbacks; |
--- |
| 2024 |
|
--- |
2024 |
|
--- |
| 2025 |
/// The vector with all simplification callbacks for global variables |
--- |
2025 |
/// The vector with all simplification callbacks for global variables |
--- |
| 2026 |
/// registered by outside AAs. |
--- |
2026 |
/// registered by outside AAs. |
--- |
| 2027 |
DenseMap
| --- |
2027 |
DenseMap
| --- |
| |
| 2028 |
SmallVector> |
--- |
2028 |
SmallVector> |
--- |
| 2029 |
GlobalVariableSimplificationCallbacks; |
--- |
2029 |
GlobalVariableSimplificationCallbacks; |
--- |
| 2030 |
|
--- |
2030 |
|
--- |
| 2031 |
DenseMap> |
--- |
2031 |
DenseMap> |
--- |
| 2032 |
VirtualUseCallbacks; |
--- |
2032 |
VirtualUseCallbacks; |
--- |
| 2033 |
|
--- |
2033 |
|
--- |
| 2034 |
public: |
--- |
2034 |
public: |
--- |
| 2035 |
/// Translate \p V from the callee context into the call site context. |
--- |
2035 |
/// Translate \p V from the callee context into the call site context. |
--- |
| 2036 |
std::optional |
--- |
2036 |
std::optional |
--- |
| 2037 |
translateArgumentToCallSiteContent(std::optional V, CallBase &CB, |
--- |
2037 |
translateArgumentToCallSiteContent(std::optional V, CallBase &CB, |
--- |
| 2038 |
const AbstractAttribute &AA, |
--- |
2038 |
const AbstractAttribute &AA, |
--- |
| 2039 |
bool &UsedAssumedInformation); |
--- |
2039 |
bool &UsedAssumedInformation); |
--- |
| 2040 |
|
--- |
2040 |
|
--- |
| 2041 |
/// Return true if \p AA (or its context instruction) is assumed dead. |
--- |
2041 |
/// Return true if \p AA (or its context instruction) is assumed dead. |
--- |
| 2042 |
/// |
--- |
2042 |
/// |
--- |
| 2043 |
/// If \p LivenessAA is not provided it is queried. |
--- |
2043 |
/// If \p LivenessAA is not provided it is queried. |
--- |
| 2044 |
bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA, |
--- |
2044 |
bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA, |
--- |
| 2045 |
bool &UsedAssumedInformation, |
--- |
2045 |
bool &UsedAssumedInformation, |
--- |
| 2046 |
bool CheckBBLivenessOnly = false, |
--- |
2046 |
bool CheckBBLivenessOnly = false, |
--- |
| 2047 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
2047 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
| 2048 |
|
--- |
2048 |
|
--- |
| 2049 |
/// Return true if \p I is assumed dead. |
--- |
2049 |
/// Return true if \p I is assumed dead. |
--- |
| 2050 |
/// |
--- |
2050 |
/// |
--- |
| 2051 |
/// If \p LivenessAA is not provided it is queried. |
--- |
2051 |
/// If \p LivenessAA is not provided it is queried. |
--- |
| 2052 |
bool isAssumedDead(const Instruction &I, const AbstractAttribute *QueryingAA, |
--- |
2052 |
bool isAssumedDead(const Instruction &I, const AbstractAttribute *QueryingAA, |
--- |
| 2053 |
const AAIsDead *LivenessAA, bool &UsedAssumedInformation, |
--- |
2053 |
const AAIsDead *LivenessAA, bool &UsedAssumedInformation, |
--- |
| 2054 |
bool CheckBBLivenessOnly = false, |
--- |
2054 |
bool CheckBBLivenessOnly = false, |
--- |
| 2055 |
DepClassTy DepClass = DepClassTy::OPTIONAL, |
--- |
2055 |
DepClassTy DepClass = DepClassTy::OPTIONAL, |
--- |
| 2056 |
bool CheckForDeadStore = false); |
--- |
2056 |
bool CheckForDeadStore = false); |
--- |
| 2057 |
|
--- |
2057 |
|
--- |
| 2058 |
/// Return true if \p U is assumed dead. |
--- |
2058 |
/// Return true if \p U is assumed dead. |
--- |
| 2059 |
/// |
--- |
2059 |
/// |
--- |
| 2060 |
/// If \p FnLivenessAA is not provided it is queried. |
--- |
2060 |
/// If \p FnLivenessAA is not provided it is queried. |
--- |
| 2061 |
bool isAssumedDead(const Use &U, const AbstractAttribute *QueryingAA, |
--- |
2061 |
bool isAssumedDead(const Use &U, const AbstractAttribute *QueryingAA, |
--- |
| 2062 |
const AAIsDead *FnLivenessAA, bool &UsedAssumedInformation, |
--- |
2062 |
const AAIsDead *FnLivenessAA, bool &UsedAssumedInformation, |
--- |
| 2063 |
bool CheckBBLivenessOnly = false, |
--- |
2063 |
bool CheckBBLivenessOnly = false, |
--- |
| 2064 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
2064 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
| 2065 |
|
--- |
2065 |
|
--- |
| 2066 |
/// Return true if \p IRP is assumed dead. |
--- |
2066 |
/// Return true if \p IRP is assumed dead. |
--- |
| 2067 |
/// |
--- |
2067 |
/// |
--- |
| 2068 |
/// If \p FnLivenessAA is not provided it is queried. |
--- |
2068 |
/// If \p FnLivenessAA is not provided it is queried. |
--- |
| 2069 |
bool isAssumedDead(const IRPosition &IRP, const AbstractAttribute *QueryingAA, |
--- |
2069 |
bool isAssumedDead(const IRPosition &IRP, const AbstractAttribute *QueryingAA, |
--- |
| 2070 |
const AAIsDead *FnLivenessAA, bool &UsedAssumedInformation, |
--- |
2070 |
const AAIsDead *FnLivenessAA, bool &UsedAssumedInformation, |
--- |
| 2071 |
bool CheckBBLivenessOnly = false, |
--- |
2071 |
bool CheckBBLivenessOnly = false, |
--- |
| 2072 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
2072 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
| 2073 |
|
--- |
2073 |
|
--- |
| 2074 |
/// Return true if \p BB is assumed dead. |
--- |
2074 |
/// Return true if \p BB is assumed dead. |
--- |
| 2075 |
/// |
--- |
2075 |
/// |
--- |
| 2076 |
/// If \p LivenessAA is not provided it is queried. |
--- |
2076 |
/// If \p LivenessAA is not provided it is queried. |
--- |
| 2077 |
bool isAssumedDead(const BasicBlock &BB, const AbstractAttribute *QueryingAA, |
--- |
2077 |
bool isAssumedDead(const BasicBlock &BB, const AbstractAttribute *QueryingAA, |
--- |
| 2078 |
const AAIsDead *FnLivenessAA, |
--- |
2078 |
const AAIsDead *FnLivenessAA, |
--- |
| 2079 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
2079 |
DepClassTy DepClass = DepClassTy::OPTIONAL); |
--- |
| 2080 |
|
--- |
2080 |
|
--- |
| 2081 |
/// Check \p Pred on all (transitive) uses of \p V. |
--- |
2081 |
/// Check \p Pred on all (transitive) uses of \p V. |
--- |
| 2082 |
/// |
--- |
2082 |
/// |
--- |
| 2083 |
/// This method will evaluate \p Pred on all (transitive) uses of the |
--- |
2083 |
/// This method will evaluate \p Pred on all (transitive) uses of the |
--- |
| 2084 |
/// associated value and return true if \p Pred holds every time. |
--- |
2084 |
/// associated value and return true if \p Pred holds every time. |
--- |
| 2085 |
/// If uses are skipped in favor of equivalent ones, e.g., if we look through |
--- |
2085 |
/// If uses are skipped in favor of equivalent ones, e.g., if we look through |
--- |
| 2086 |
/// memory, the \p EquivalentUseCB will be used to give the caller an idea |
--- |
2086 |
/// memory, the \p EquivalentUseCB will be used to give the caller an idea |
--- |
| 2087 |
/// what original used was replaced by a new one (or new ones). The visit is |
--- |
2087 |
/// what original used was replaced by a new one (or new ones). The visit is |
--- |
| 2088 |
/// cut short if \p EquivalentUseCB returns false and the function will return |
--- |
2088 |
/// cut short if \p EquivalentUseCB returns false and the function will return |
--- |
| 2089 |
/// false as well. |
--- |
2089 |
/// false as well. |
--- |
| 2090 |
bool checkForAllUses(function_ref Pred, |
--- |
2090 |
bool checkForAllUses(function_ref Pred, |
--- |
| 2091 |
const AbstractAttribute &QueryingAA, const Value &V, |
--- |
2091 |
const AbstractAttribute &QueryingAA, const Value &V, |
--- |
| 2092 |
bool CheckBBLivenessOnly = false, |
--- |
2092 |
bool CheckBBLivenessOnly = false, |
--- |
| 2093 |
DepClassTy LivenessDepClass = DepClassTy::OPTIONAL, |
--- |
2093 |
DepClassTy LivenessDepClass = DepClassTy::OPTIONAL, |
--- |
| 2094 |
bool IgnoreDroppableUses = true, |
--- |
2094 |
bool IgnoreDroppableUses = true, |
--- |
| 2095 |
function_ref |
--- |
2095 |
function_ref |
--- |
| 2096 |
EquivalentUseCB = nullptr); |
--- |
2096 |
EquivalentUseCB = nullptr); |
--- |
| 2097 |
|
--- |
2097 |
|
--- |
| 2098 |
/// Emit a remark generically. |
--- |
2098 |
/// Emit a remark generically. |
--- |
| 2099 |
/// |
--- |
2099 |
/// |
--- |
| 2100 |
/// This template function can be used to generically emit a remark. The |
--- |
2100 |
/// This template function can be used to generically emit a remark. The |
--- |
| 2101 |
/// RemarkKind should be one of the following: |
--- |
2101 |
/// RemarkKind should be one of the following: |
--- |
| 2102 |
/// - OptimizationRemark to indicate a successful optimization attempt |
--- |
2102 |
/// - OptimizationRemark to indicate a successful optimization attempt |
--- |
| 2103 |
/// - OptimizationRemarkMissed to report a failed optimization attempt |
--- |
2103 |
/// - OptimizationRemarkMissed to report a failed optimization attempt |
--- |
| 2104 |
/// - OptimizationRemarkAnalysis to provide additional information about an |
--- |
2104 |
/// - OptimizationRemarkAnalysis to provide additional information about an |
--- |
| 2105 |
/// optimization attempt |
--- |
2105 |
/// optimization attempt |
--- |
| 2106 |
/// |
--- |
2106 |
/// |
--- |
| 2107 |
/// The remark is built using a callback function \p RemarkCB that takes a |
--- |
2107 |
/// The remark is built using a callback function \p RemarkCB that takes a |
--- |
| 2108 |
/// RemarkKind as input and returns a RemarkKind. |
--- |
2108 |
/// RemarkKind as input and returns a RemarkKind. |
--- |
| 2109 |
template |
--- |
2109 |
template |
--- |
| 2110 |
void emitRemark(Instruction *I, StringRef RemarkName, |
--- |
2110 |
void emitRemark(Instruction *I, StringRef RemarkName, |
--- |
| 2111 |
RemarkCallBack &&RemarkCB) const { |
--- |
2111 |
RemarkCallBack &&RemarkCB) const { |
--- |
| 2112 |
if (!Configuration.OREGetter) |
--- |
2112 |
if (!Configuration.OREGetter) |
--- |
| 2113 |
return; |
--- |
2113 |
return; |
--- |
| 2114 |
|
--- |
2114 |
|
--- |
| 2115 |
Function *F = I->getFunction(); |
--- |
2115 |
Function *F = I->getFunction(); |
--- |
| 2116 |
auto &ORE = Configuration.OREGetter(F); |
--- |
2116 |
auto &ORE = Configuration.OREGetter(F); |
--- |
| 2117 |
|
--- |
2117 |
|
--- |
| 2118 |
if (RemarkName.startswith("OMP")) |
--- |
2118 |
if (RemarkName.startswith("OMP")) |
--- |
| 2119 |
ORE.emit([&]() { |
--- |
2119 |
ORE.emit([&]() { |
--- |
| 2120 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I)) |
--- |
2120 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I)) |
--- |
| 2121 |
<< " [" << RemarkName << "]"; |
--- |
2121 |
<< " [" << RemarkName << "]"; |
--- |
| 2122 |
}); |
--- |
2122 |
}); |
--- |
| 2123 |
else |
--- |
2123 |
else |
--- |
| 2124 |
ORE.emit([&]() { |
--- |
2124 |
ORE.emit([&]() { |
--- |
| 2125 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I)); |
--- |
2125 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I)); |
--- |
| 2126 |
}); |
--- |
2126 |
}); |
--- |
| 2127 |
} |
--- |
2127 |
} |
--- |
| 2128 |
|
--- |
2128 |
|
--- |
| 2129 |
/// Emit a remark on a function. |
--- |
2129 |
/// Emit a remark on a function. |
--- |
| 2130 |
template |
--- |
2130 |
template |
--- |
| 2131 |
void emitRemark(Function *F, StringRef RemarkName, |
0 |
2131 |
void emitRemark(Function *F, StringRef RemarkName, |
0 |
| 2132 |
RemarkCallBack &&RemarkCB) const { |
--- |
2132 |
RemarkCallBack &&RemarkCB) const { |
--- |
| 2133 |
if (!Configuration.OREGetter) |
0 |
2133 |
if (!Configuration.OREGetter) |
0 |
| 2134 |
return; |
0 |
2134 |
return; |
0 |
| 2135 |
|
--- |
2135 |
|
--- |
| 2136 |
auto &ORE = Configuration.OREGetter(F); |
0 |
2136 |
auto &ORE = Configuration.OREGetter(F); |
0 |
| 2137 |
|
--- |
2137 |
|
--- |
| 2138 |
if (RemarkName.startswith("OMP")) |
0 |
2138 |
if (RemarkName.startswith("OMP")) |
0 |
| 2139 |
ORE.emit([&]() { |
0 |
2139 |
ORE.emit([&]() { |
0 |
| 2140 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F)) |
0 |
2140 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F)) |
0 |
| 2141 |
<< " [" << RemarkName << "]"; |
0 |
2141 |
<< " [" << RemarkName << "]"; |
0 |
| 2142 |
}); |
--- |
2142 |
}); |
--- |
| 2143 |
else |
--- |
2143 |
else |
--- |
| 2144 |
ORE.emit([&]() { |
0 |
2144 |
ORE.emit([&]() { |
0 |
| 2145 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F)); |
0 |
2145 |
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F)); |
0 |
| 2146 |
}); |
--- |
2146 |
}); |
--- |
| 2147 |
} |
--- |
2147 |
} |
--- |
| 2148 |
|
--- |
2148 |
|
--- |
| 2149 |
/// Helper struct used in the communication between an abstract attribute (AA) |
--- |
2149 |
/// Helper struct used in the communication between an abstract attribute (AA) |
--- |
| 2150 |
/// that wants to change the signature of a function and the Attributor which |
--- |
2150 |
/// that wants to change the signature of a function and the Attributor which |
--- |
| 2151 |
/// applies the changes. The struct is partially initialized with the |
--- |
2151 |
/// applies the changes. The struct is partially initialized with the |
--- |
| 2152 |
/// information from the AA (see the constructor). All other members are |
--- |
2152 |
/// information from the AA (see the constructor). All other members are |
--- |
| 2153 |
/// provided by the Attributor prior to invoking any callbacks. |
--- |
2153 |
/// provided by the Attributor prior to invoking any callbacks. |
--- |
| 2154 |
struct ArgumentReplacementInfo { |
--- |
2154 |
struct ArgumentReplacementInfo { |
--- |
| 2155 |
/// Callee repair callback type |
--- |
2155 |
/// Callee repair callback type |
--- |
| 2156 |
/// |
--- |
2156 |
/// |
--- |
| 2157 |
/// The function repair callback is invoked once to rewire the replacement |
--- |
2157 |
/// The function repair callback is invoked once to rewire the replacement |
--- |
| 2158 |
/// arguments in the body of the new function. The argument replacement info |
--- |
2158 |
/// arguments in the body of the new function. The argument replacement info |
--- |
| 2159 |
/// is passed, as build from the registerFunctionSignatureRewrite call, as |
--- |
2159 |
/// is passed, as build from the registerFunctionSignatureRewrite call, as |
--- |
| 2160 |
/// well as the replacement function and an iteratore to the first |
--- |
2160 |
/// well as the replacement function and an iteratore to the first |
--- |
| 2161 |
/// replacement argument. |
--- |
2161 |
/// replacement argument. |
--- |
| 2162 |
using CalleeRepairCBTy = std::function
| --- |
2162 |
using CalleeRepairCBTy = std::function
| --- |
| |
| 2163 |
const ArgumentReplacementInfo &, Function &, Function::arg_iterator)>; |
--- |
2163 |
const ArgumentReplacementInfo &, Function &, Function::arg_iterator)>; |
--- |
| 2164 |
|
--- |
2164 |
|
--- |
| 2165 |
/// Abstract call site (ACS) repair callback type |
--- |
2165 |
/// Abstract call site (ACS) repair callback type |
--- |
| 2166 |
/// |
--- |
2166 |
/// |
--- |
| 2167 |
/// The abstract call site repair callback is invoked once on every abstract |
--- |
2167 |
/// The abstract call site repair callback is invoked once on every abstract |
--- |
| 2168 |
/// call site of the replaced function (\see ReplacedFn). The callback needs |
--- |
2168 |
/// call site of the replaced function (\see ReplacedFn). The callback needs |
--- |
| 2169 |
/// to provide the operands for the call to the new replacement function. |
--- |
2169 |
/// to provide the operands for the call to the new replacement function. |
--- |
| 2170 |
/// The number and type of the operands appended to the provided vector |
--- |
2170 |
/// The number and type of the operands appended to the provided vector |
--- |
| 2171 |
/// (second argument) is defined by the number and types determined through |
--- |
2171 |
/// (second argument) is defined by the number and types determined through |
--- |
| 2172 |
/// the replacement type vector (\see ReplacementTypes). The first argument |
--- |
2172 |
/// the replacement type vector (\see ReplacementTypes). The first argument |
--- |
| 2173 |
/// is the ArgumentReplacementInfo object registered with the Attributor |
--- |
2173 |
/// is the ArgumentReplacementInfo object registered with the Attributor |
--- |
| 2174 |
/// through the registerFunctionSignatureRewrite call. |
--- |
2174 |
/// through the registerFunctionSignatureRewrite call. |
--- |
| 2175 |
using ACSRepairCBTy = |
--- |
2175 |
using ACSRepairCBTy = |
--- |
| 2176 |
std::function
| --- |
2176 |
std::function
| --- |
| |
| 2177 |
SmallVectorImpl &)>; |
--- |
2177 |
SmallVectorImpl &)>; |
--- |
| 2178 |
|
--- |
2178 |
|
--- |
| 2179 |
/// Simple getters, see the corresponding members for details. |
--- |
2179 |
/// Simple getters, see the corresponding members for details. |
--- |
| 2180 |
///{ |
--- |
2180 |
///{ |
--- |
| 2181 |
|
--- |
2181 |
|
--- |
| 2182 |
Attributor &getAttributor() const { return A; } |
--- |
2182 |
Attributor &getAttributor() const { return A; } |
--- |
| 2183 |
const Function &getReplacedFn() const { return ReplacedFn; } |
--- |
2183 |
const Function &getReplacedFn() const { return ReplacedFn; } |
--- |
| 2184 |
const Argument &getReplacedArg() const { return ReplacedArg; } |
--- |
2184 |
const Argument &getReplacedArg() const { return ReplacedArg; } |
--- |
| 2185 |
unsigned getNumReplacementArgs() const { return ReplacementTypes.size(); } |
0 |
2185 |
unsigned getNumReplacementArgs() const { return ReplacementTypes.size(); } |
0 |
| 2186 |
const SmallVectorImpl &getReplacementTypes() const { |
--- |
2186 |
const SmallVectorImpl &getReplacementTypes() const { |
--- |
| 2187 |
return ReplacementTypes; |
--- |
2187 |
return ReplacementTypes; |
--- |
| 2188 |
} |
--- |
2188 |
} |
--- |
| 2189 |
|
--- |
2189 |
|
--- |
| 2190 |
///} |
--- |
2190 |
///} |
--- |
| 2191 |
|
--- |
2191 |
|
--- |
| 2192 |
private: |
--- |
2192 |
private: |
--- |
| 2193 |
/// Constructor that takes the argument to be replaced, the types of |
--- |
2193 |
/// Constructor that takes the argument to be replaced, the types of |
--- |
| 2194 |
/// the replacement arguments, as well as callbacks to repair the call sites |
--- |
2194 |
/// the replacement arguments, as well as callbacks to repair the call sites |
--- |
| 2195 |
/// and new function after the replacement happened. |
--- |
2195 |
/// and new function after the replacement happened. |
--- |
| 2196 |
ArgumentReplacementInfo(Attributor &A, Argument &Arg, |
0 |
2196 |
ArgumentReplacementInfo(Attributor &A, Argument &Arg, |
0 |
| 2197 |
ArrayRef ReplacementTypes, |
--- |
2197 |
ArrayRef ReplacementTypes, |
--- |
| 2198 |
CalleeRepairCBTy &&CalleeRepairCB, |
--- |
2198 |
CalleeRepairCBTy &&CalleeRepairCB, |
--- |
| 2199 |
ACSRepairCBTy &&ACSRepairCB) |
--- |
2199 |
ACSRepairCBTy &&ACSRepairCB) |
--- |
| 2200 |
: A(A), ReplacedFn(*Arg.getParent()), ReplacedArg(Arg), |
0 |
2200 |
: A(A), ReplacedFn(*Arg.getParent()), ReplacedArg(Arg), |
0 |
| 2201 |
ReplacementTypes(ReplacementTypes.begin(), ReplacementTypes.end()), |
0 |
2201 |
ReplacementTypes(ReplacementTypes.begin(), ReplacementTypes.end()), |
0 |
| 2202 |
CalleeRepairCB(std::move(CalleeRepairCB)), |
0 |
2202 |
CalleeRepairCB(std::move(CalleeRepairCB)), |
0 |
| 2203 |
ACSRepairCB(std::move(ACSRepairCB)) {} |
0 |
2203 |
ACSRepairCB(std::move(ACSRepairCB)) {} |
0 |
| 2204 |
|
--- |
2204 |
|
--- |
| 2205 |
/// Reference to the attributor to allow access from the callbacks. |
--- |
2205 |
/// Reference to the attributor to allow access from the callbacks. |
--- |
| 2206 |
Attributor &A; |
--- |
2206 |
Attributor &A; |
--- |
| 2207 |
|
--- |
2207 |
|
--- |
| 2208 |
/// The "old" function replaced by ReplacementFn. |
--- |
2208 |
/// The "old" function replaced by ReplacementFn. |
--- |
| 2209 |
const Function &ReplacedFn; |
--- |
2209 |
const Function &ReplacedFn; |
--- |
| 2210 |
|
--- |
2210 |
|
--- |
| 2211 |
/// The "old" argument replaced by new ones defined via ReplacementTypes. |
--- |
2211 |
/// The "old" argument replaced by new ones defined via ReplacementTypes. |
--- |
| 2212 |
const Argument &ReplacedArg; |
--- |
2212 |
const Argument &ReplacedArg; |
--- |
| 2213 |
|
--- |
2213 |
|
--- |
| 2214 |
/// The types of the arguments replacing ReplacedArg. |
--- |
2214 |
/// The types of the arguments replacing ReplacedArg. |
--- |
| 2215 |
const SmallVector ReplacementTypes; |
--- |
2215 |
const SmallVector ReplacementTypes; |
--- |
| 2216 |
|
--- |
2216 |
|
--- |
| 2217 |
/// Callee repair callback, see CalleeRepairCBTy. |
--- |
2217 |
/// Callee repair callback, see CalleeRepairCBTy. |
--- |
| 2218 |
const CalleeRepairCBTy CalleeRepairCB; |
--- |
2218 |
const CalleeRepairCBTy CalleeRepairCB; |
--- |
| 2219 |
|
--- |
2219 |
|
--- |
| 2220 |
/// Abstract call site (ACS) repair callback, see ACSRepairCBTy. |
--- |
2220 |
/// Abstract call site (ACS) repair callback, see ACSRepairCBTy. |
--- |
| 2221 |
const ACSRepairCBTy ACSRepairCB; |
--- |
2221 |
const ACSRepairCBTy ACSRepairCB; |
--- |
| 2222 |
|
--- |
2222 |
|
--- |
| 2223 |
/// Allow access to the private members from the Attributor. |
--- |
2223 |
/// Allow access to the private members from the Attributor. |
--- |
| 2224 |
friend struct Attributor; |
--- |
2224 |
friend struct Attributor; |
--- |
| 2225 |
}; |
--- |
2225 |
}; |
--- |
| 2226 |
|
--- |
2226 |
|
--- |
| 2227 |
/// Check if we can rewrite a function signature. |
--- |
2227 |
/// Check if we can rewrite a function signature. |
--- |
| 2228 |
/// |
--- |
2228 |
/// |
--- |
| 2229 |
/// The argument \p Arg is replaced with new ones defined by the number, |
--- |
2229 |
/// The argument \p Arg is replaced with new ones defined by the number, |
--- |
| 2230 |
/// order, and types in \p ReplacementTypes. |
--- |
2230 |
/// order, and types in \p ReplacementTypes. |
--- |
| 2231 |
/// |
--- |
2231 |
/// |
--- |
| 2232 |
/// \returns True, if the replacement can be registered, via |
--- |
2232 |
/// \returns True, if the replacement can be registered, via |
--- |
| 2233 |
/// registerFunctionSignatureRewrite, false otherwise. |
--- |
2233 |
/// registerFunctionSignatureRewrite, false otherwise. |
--- |
| 2234 |
bool isValidFunctionSignatureRewrite(Argument &Arg, |
--- |
2234 |
bool isValidFunctionSignatureRewrite(Argument &Arg, |
--- |
| 2235 |
ArrayRef ReplacementTypes); |
--- |
2235 |
ArrayRef ReplacementTypes); |
--- |
| 2236 |
|
--- |
2236 |
|
--- |
| 2237 |
/// Register a rewrite for a function signature. |
--- |
2237 |
/// Register a rewrite for a function signature. |
--- |
| 2238 |
/// |
--- |
2238 |
/// |
--- |
| 2239 |
/// The argument \p Arg is replaced with new ones defined by the number, |
--- |
2239 |
/// The argument \p Arg is replaced with new ones defined by the number, |
--- |
| 2240 |
/// order, and types in \p ReplacementTypes. The rewiring at the call sites is |
--- |
2240 |
/// order, and types in \p ReplacementTypes. The rewiring at the call sites is |
--- |
| 2241 |
/// done through \p ACSRepairCB and at the callee site through |
--- |
2241 |
/// done through \p ACSRepairCB and at the callee site through |
--- |
| 2242 |
/// \p CalleeRepairCB. |
--- |
2242 |
/// \p CalleeRepairCB. |
--- |
| 2243 |
/// |
--- |
2243 |
/// |
--- |
| 2244 |
/// \returns True, if the replacement was registered, false otherwise. |
--- |
2244 |
/// \returns True, if the replacement was registered, false otherwise. |
--- |
| 2245 |
bool registerFunctionSignatureRewrite( |
--- |
2245 |
bool registerFunctionSignatureRewrite( |
--- |
| 2246 |
Argument &Arg, ArrayRef ReplacementTypes, |
--- |
2246 |
Argument &Arg, ArrayRef ReplacementTypes, |
--- |
| 2247 |
ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, |
--- |
2247 |
ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, |
--- |
| 2248 |
ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB); |
--- |
2248 |
ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB); |
--- |
| 2249 |
|
--- |
2249 |
|
--- |
| 2250 |
/// Check \p Pred on all function call sites. |
--- |
2250 |
/// Check \p Pred on all function call sites. |
--- |
| 2251 |
/// |
--- |
2251 |
/// |
--- |
| 2252 |
/// This method will evaluate \p Pred on call sites and return |
--- |
2252 |
/// This method will evaluate \p Pred on call sites and return |
--- |
| 2253 |
/// true if \p Pred holds in every call sites. However, this is only possible |
--- |
2253 |
/// true if \p Pred holds in every call sites. However, this is only possible |
--- |
| 2254 |
/// all call sites are known, hence the function has internal linkage. |
--- |
2254 |
/// all call sites are known, hence the function has internal linkage. |
--- |
| 2255 |
/// If true is returned, \p UsedAssumedInformation is set if assumed |
--- |
2255 |
/// If true is returned, \p UsedAssumedInformation is set if assumed |
--- |
| 2256 |
/// information was used to skip or simplify potential call sites. |
--- |
2256 |
/// information was used to skip or simplify potential call sites. |
--- |
| 2257 |
bool checkForAllCallSites(function_ref Pred, |
--- |
2257 |
bool checkForAllCallSites(function_ref Pred, |
--- |
| 2258 |
const AbstractAttribute &QueryingAA, |
--- |
2258 |
const AbstractAttribute &QueryingAA, |
--- |
| 2259 |
bool RequireAllCallSites, |
--- |
2259 |
bool RequireAllCallSites, |
--- |
| 2260 |
bool &UsedAssumedInformation); |
--- |
2260 |
bool &UsedAssumedInformation); |
--- |
| 2261 |
|
--- |
2261 |
|
--- |
| 2262 |
/// Check \p Pred on all call sites of \p Fn. |
--- |
2262 |
/// Check \p Pred on all call sites of \p Fn. |
--- |
| 2263 |
/// |
--- |
2263 |
/// |
--- |
| 2264 |
/// This method will evaluate \p Pred on call sites and return |
--- |
2264 |
/// This method will evaluate \p Pred on call sites and return |
--- |
| 2265 |
/// true if \p Pred holds in every call sites. However, this is only possible |
--- |
2265 |
/// true if \p Pred holds in every call sites. However, this is only possible |
--- |
| 2266 |
/// all call sites are known, hence the function has internal linkage. |
--- |
2266 |
/// all call sites are known, hence the function has internal linkage. |
--- |
| 2267 |
/// If true is returned, \p UsedAssumedInformation is set if assumed |
--- |
2267 |
/// If true is returned, \p UsedAssumedInformation is set if assumed |
--- |
| 2268 |
/// information was used to skip or simplify potential call sites. |
--- |
2268 |
/// information was used to skip or simplify potential call sites. |
--- |
| 2269 |
bool checkForAllCallSites(function_ref Pred, |
--- |
2269 |
bool checkForAllCallSites(function_ref Pred, |
--- |
| 2270 |
const Function &Fn, bool RequireAllCallSites, |
--- |
2270 |
const Function &Fn, bool RequireAllCallSites, |
--- |
| 2271 |
const AbstractAttribute *QueryingAA, |
--- |
2271 |
const AbstractAttribute *QueryingAA, |
--- |
| 2272 |
bool &UsedAssumedInformation, |
--- |
2272 |
bool &UsedAssumedInformation, |
--- |
| 2273 |
bool CheckPotentiallyDead = false); |
--- |
2273 |
bool CheckPotentiallyDead = false); |
--- |
| 2274 |
|
--- |
2274 |
|
--- |
| 2275 |
/// Check \p Pred on all values potentially returned by the function |
--- |
2275 |
/// Check \p Pred on all values potentially returned by the function |
--- |
| 2276 |
/// associated with \p QueryingAA. |
--- |
2276 |
/// associated with \p QueryingAA. |
--- |
| 2277 |
/// |
--- |
2277 |
/// |
--- |
| 2278 |
/// This is the context insensitive version of the method above. |
--- |
2278 |
/// This is the context insensitive version of the method above. |
--- |
| 2279 |
bool |
--- |
2279 |
bool |
--- |
| 2280 |
checkForAllReturnedValues(function_ref Pred, |
--- |
2280 |
checkForAllReturnedValues(function_ref Pred, |
--- |
| 2281 |
const AbstractAttribute &QueryingAA, |
--- |
2281 |
const AbstractAttribute &QueryingAA, |
--- |
| 2282 |
AA::ValueScope S = AA::ValueScope::Intraprocedural, |
--- |
2282 |
AA::ValueScope S = AA::ValueScope::Intraprocedural, |
--- |
| 2283 |
bool RecurseForSelectAndPHI = true); |
--- |
2283 |
bool RecurseForSelectAndPHI = true); |
--- |
| 2284 |
|
--- |
2284 |
|
--- |
| 2285 |
/// Check \p Pred on all instructions in \p Fn with an opcode present in |
--- |
2285 |
/// Check \p Pred on all instructions in \p Fn with an opcode present in |
--- |
| 2286 |
/// \p Opcodes. |
--- |
2286 |
/// \p Opcodes. |
--- |
| 2287 |
/// |
--- |
2287 |
/// |
--- |
| 2288 |
/// This method will evaluate \p Pred on all instructions with an opcode |
--- |
2288 |
/// This method will evaluate \p Pred on all instructions with an opcode |
--- |
| 2289 |
/// present in \p Opcode and return true if \p Pred holds on all of them. |
--- |
2289 |
/// present in \p Opcode and return true if \p Pred holds on all of them. |
--- |
| 2290 |
bool checkForAllInstructions(function_ref Pred, |
--- |
2290 |
bool checkForAllInstructions(function_ref Pred, |
--- |
| 2291 |
const Function *Fn, |
--- |
2291 |
const Function *Fn, |
--- |
| 2292 |
const AbstractAttribute *QueryingAA, |
--- |
2292 |
const AbstractAttribute *QueryingAA, |
--- |
| 2293 |
const ArrayRef &Opcodes, |
--- |
2293 |
const ArrayRef &Opcodes, |
--- |
| 2294 |
bool &UsedAssumedInformation, |
--- |
2294 |
bool &UsedAssumedInformation, |
--- |
| 2295 |
bool CheckBBLivenessOnly = false, |
--- |
2295 |
bool CheckBBLivenessOnly = false, |
--- |
| 2296 |
bool CheckPotentiallyDead = false); |
--- |
2296 |
bool CheckPotentiallyDead = false); |
--- |
| 2297 |
|
--- |
2297 |
|
--- |
| 2298 |
/// Check \p Pred on all instructions with an opcode present in \p Opcodes. |
--- |
2298 |
/// Check \p Pred on all instructions with an opcode present in \p Opcodes. |
--- |
| 2299 |
/// |
--- |
2299 |
/// |
--- |
| 2300 |
/// This method will evaluate \p Pred on all instructions with an opcode |
--- |
2300 |
/// This method will evaluate \p Pred on all instructions with an opcode |
--- |
| 2301 |
/// present in \p Opcode and return true if \p Pred holds on all of them. |
--- |
2301 |
/// present in \p Opcode and return true if \p Pred holds on all of them. |
--- |
| 2302 |
bool checkForAllInstructions(function_ref Pred, |
--- |
2302 |
bool checkForAllInstructions(function_ref Pred, |
--- |
| 2303 |
const AbstractAttribute &QueryingAA, |
--- |
2303 |
const AbstractAttribute &QueryingAA, |
--- |
| 2304 |
const ArrayRef &Opcodes, |
--- |
2304 |
const ArrayRef &Opcodes, |
--- |
| 2305 |
bool &UsedAssumedInformation, |
--- |
2305 |
bool &UsedAssumedInformation, |
--- |
| 2306 |
bool CheckBBLivenessOnly = false, |
--- |
2306 |
bool CheckBBLivenessOnly = false, |
--- |
| 2307 |
bool CheckPotentiallyDead = false); |
--- |
2307 |
bool CheckPotentiallyDead = false); |
--- |
| 2308 |
|
--- |
2308 |
|
--- |
| 2309 |
/// Check \p Pred on all call-like instructions (=CallBased derived). |
--- |
2309 |
/// Check \p Pred on all call-like instructions (=CallBased derived). |
--- |
| 2310 |
/// |
--- |
2310 |
/// |
--- |
| 2311 |
/// See checkForAllCallLikeInstructions(...) for more information. |
--- |
2311 |
/// See checkForAllCallLikeInstructions(...) for more information. |
--- |
| 2312 |
bool checkForAllCallLikeInstructions(function_ref Pred, |
--- |
2312 |
bool checkForAllCallLikeInstructions(function_ref Pred, |
--- |
| 2313 |
const AbstractAttribute &QueryingAA, |
--- |
2313 |
const AbstractAttribute &QueryingAA, |
--- |
| 2314 |
bool &UsedAssumedInformation, |
--- |
2314 |
bool &UsedAssumedInformation, |
--- |
| 2315 |
bool CheckBBLivenessOnly = false, |
--- |
2315 |
bool CheckBBLivenessOnly = false, |
--- |
| 2316 |
bool CheckPotentiallyDead = false) { |
--- |
2316 |
bool CheckPotentiallyDead = false) { |
--- |
| 2317 |
return checkForAllInstructions( |
--- |
2317 |
return checkForAllInstructions( |
--- |
| 2318 |
Pred, QueryingAA, |
--- |
2318 |
Pred, QueryingAA, |
--- |
| 2319 |
{(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr, |
--- |
2319 |
{(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr, |
--- |
| 2320 |
(unsigned)Instruction::Call}, |
--- |
2320 |
(unsigned)Instruction::Call}, |
--- |
| 2321 |
UsedAssumedInformation, CheckBBLivenessOnly, CheckPotentiallyDead); |
--- |
2321 |
UsedAssumedInformation, CheckBBLivenessOnly, CheckPotentiallyDead); |
--- |
| 2322 |
} |
--- |
2322 |
} |
--- |
| 2323 |
|
--- |
2323 |
|
--- |
| 2324 |
/// Check \p Pred on all Read/Write instructions. |
--- |
2324 |
/// Check \p Pred on all Read/Write instructions. |
--- |
| 2325 |
/// |
--- |
2325 |
/// |
--- |
| 2326 |
/// This method will evaluate \p Pred on all instructions that read or write |
--- |
2326 |
/// This method will evaluate \p Pred on all instructions that read or write |
--- |
| 2327 |
/// to memory present in the information cache and return true if \p Pred |
--- |
2327 |
/// to memory present in the information cache and return true if \p Pred |
--- |
| 2328 |
/// holds on all of them. |
--- |
2328 |
/// holds on all of them. |
--- |
| 2329 |
bool checkForAllReadWriteInstructions(function_ref Pred, |
--- |
2329 |
bool checkForAllReadWriteInstructions(function_ref Pred, |
--- |
| 2330 |
AbstractAttribute &QueryingAA, |
--- |
2330 |
AbstractAttribute &QueryingAA, |
--- |
| 2331 |
bool &UsedAssumedInformation); |
--- |
2331 |
bool &UsedAssumedInformation); |
--- |
| 2332 |
|
--- |
2332 |
|
--- |
| 2333 |
/// Create a shallow wrapper for \p F such that \p F has internal linkage |
--- |
2333 |
/// Create a shallow wrapper for \p F such that \p F has internal linkage |
--- |
| 2334 |
/// afterwards. It also sets the original \p F 's name to anonymous |
--- |
2334 |
/// afterwards. It also sets the original \p F 's name to anonymous |
--- |
| 2335 |
/// |
--- |
2335 |
/// |
--- |
| 2336 |
/// A wrapper is a function with the same type (and attributes) as \p F |
--- |
2336 |
/// A wrapper is a function with the same type (and attributes) as \p F |
--- |
| 2337 |
/// that will only call \p F and return the result, if any. |
--- |
2337 |
/// that will only call \p F and return the result, if any. |
--- |
| 2338 |
/// |
--- |
2338 |
/// |
--- |
| 2339 |
/// Assuming the declaration of looks like: |
--- |
2339 |
/// Assuming the declaration of looks like: |
--- |
| 2340 |
/// rty F(aty0 arg0, ..., atyN argN); |
--- |
2340 |
/// rty F(aty0 arg0, ..., atyN argN); |
--- |
| 2341 |
/// |
--- |
2341 |
/// |
--- |
| 2342 |
/// The wrapper will then look as follows: |
--- |
2342 |
/// The wrapper will then look as follows: |
--- |
| 2343 |
/// rty wrapper(aty0 arg0, ..., atyN argN) { |
--- |
2343 |
/// rty wrapper(aty0 arg0, ..., atyN argN) { |
--- |
| 2344 |
/// return F(arg0, ..., argN); |
--- |
2344 |
/// return F(arg0, ..., argN); |
--- |
| 2345 |
/// } |
--- |
2345 |
/// } |
--- |
| 2346 |
/// |
--- |
2346 |
/// |
--- |
| 2347 |
static void createShallowWrapper(Function &F); |
--- |
2347 |
static void createShallowWrapper(Function &F); |
--- |
| 2348 |
|
--- |
2348 |
|
--- |
| 2349 |
/// Returns true if the function \p F can be internalized. i.e. it has a |
--- |
2349 |
/// Returns true if the function \p F can be internalized. i.e. it has a |
--- |
| 2350 |
/// compatible linkage. |
--- |
2350 |
/// compatible linkage. |
--- |
| 2351 |
static bool isInternalizable(Function &F); |
--- |
2351 |
static bool isInternalizable(Function &F); |
--- |
| 2352 |
|
--- |
2352 |
|
--- |
| 2353 |
/// Make another copy of the function \p F such that the copied version has |
--- |
2353 |
/// Make another copy of the function \p F such that the copied version has |
--- |
| 2354 |
/// internal linkage afterwards and can be analysed. Then we replace all uses |
--- |
2354 |
/// internal linkage afterwards and can be analysed. Then we replace all uses |
--- |
| 2355 |
/// of the original function to the copied one |
--- |
2355 |
/// of the original function to the copied one |
--- |
| 2356 |
/// |
--- |
2356 |
/// |
--- |
| 2357 |
/// Only non-locally linked functions that have `linkonce_odr` or `weak_odr` |
--- |
2357 |
/// Only non-locally linked functions that have `linkonce_odr` or `weak_odr` |
--- |
| 2358 |
/// linkage can be internalized because these linkages guarantee that other |
--- |
2358 |
/// linkage can be internalized because these linkages guarantee that other |
--- |
| 2359 |
/// definitions with the same name have the same semantics as this one. |
--- |
2359 |
/// definitions with the same name have the same semantics as this one. |
--- |
| 2360 |
/// |
--- |
2360 |
/// |
--- |
| 2361 |
/// This will only be run if the `attributor-allow-deep-wrappers` option is |
--- |
2361 |
/// This will only be run if the `attributor-allow-deep-wrappers` option is |
--- |
| 2362 |
/// set, or if the function is called with \p Force set to true. |
--- |
2362 |
/// set, or if the function is called with \p Force set to true. |
--- |
| 2363 |
/// |
--- |
2363 |
/// |
--- |
| 2364 |
/// If the function \p F failed to be internalized the return value will be a |
--- |
2364 |
/// If the function \p F failed to be internalized the return value will be a |
--- |
| 2365 |
/// null pointer. |
--- |
2365 |
/// null pointer. |
--- |
| 2366 |
static Function *internalizeFunction(Function &F, bool Force = false); |
--- |
2366 |
static Function *internalizeFunction(Function &F, bool Force = false); |
--- |
| 2367 |
|
--- |
2367 |
|
--- |
| 2368 |
/// Make copies of each function in the set \p FnSet such that the copied |
--- |
2368 |
/// Make copies of each function in the set \p FnSet such that the copied |
--- |
| 2369 |
/// version has internal linkage afterwards and can be analysed. Then we |
--- |
2369 |
/// version has internal linkage afterwards and can be analysed. Then we |
--- |
| 2370 |
/// replace all uses of the original function to the copied one. The map |
--- |
2370 |
/// replace all uses of the original function to the copied one. The map |
--- |
| 2371 |
/// \p FnMap contains a mapping of functions to their internalized versions. |
--- |
2371 |
/// \p FnMap contains a mapping of functions to their internalized versions. |
--- |
| 2372 |
/// |
--- |
2372 |
/// |
--- |
| 2373 |
/// Only non-locally linked functions that have `linkonce_odr` or `weak_odr` |
--- |
2373 |
/// Only non-locally linked functions that have `linkonce_odr` or `weak_odr` |
--- |
| 2374 |
/// linkage can be internalized because these linkages guarantee that other |
--- |
2374 |
/// linkage can be internalized because these linkages guarantee that other |
--- |
| 2375 |
/// definitions with the same name have the same semantics as this one. |
--- |
2375 |
/// definitions with the same name have the same semantics as this one. |
--- |
| 2376 |
/// |
--- |
2376 |
/// |
--- |
| 2377 |
/// This version will internalize all the functions in the set \p FnSet at |
--- |
2377 |
/// This version will internalize all the functions in the set \p FnSet at |
--- |
| 2378 |
/// once and then replace the uses. This prevents internalized functions being |
--- |
2378 |
/// once and then replace the uses. This prevents internalized functions being |
--- |
| 2379 |
/// called by external functions when there is an internalized version in the |
--- |
2379 |
/// called by external functions when there is an internalized version in the |
--- |
| 2380 |
/// module. |
--- |
2380 |
/// module. |
--- |
| 2381 |
static bool internalizeFunctions(SmallPtrSetImpl &FnSet, |
--- |
2381 |
static bool internalizeFunctions(SmallPtrSetImpl &FnSet, |
--- |
| 2382 |
DenseMap &FnMap); |
--- |
2382 |
DenseMap &FnMap); |
--- |
| 2383 |
|
--- |
2383 |
|
--- |
| 2384 |
/// Return the data layout associated with the anchor scope. |
--- |
2384 |
/// Return the data layout associated with the anchor scope. |
--- |
| 2385 |
const DataLayout &getDataLayout() const { return InfoCache.DL; } |
0 |
2385 |
const DataLayout &getDataLayout() const { return InfoCache.DL; } |
0 |
| 2386 |
|
--- |
2386 |
|
--- |
| 2387 |
/// The allocator used to allocate memory, e.g. for `AbstractAttribute`s. |
--- |
2387 |
/// The allocator used to allocate memory, e.g. for `AbstractAttribute`s. |
--- |
| 2388 |
BumpPtrAllocator &Allocator; |
--- |
2388 |
BumpPtrAllocator &Allocator; |
--- |
| 2389 |
|
--- |
2389 |
|
--- |
| 2390 |
private: |
--- |
2390 |
private: |
--- |
| 2391 |
/// This method will do fixpoint iteration until fixpoint or the |
--- |
2391 |
/// This method will do fixpoint iteration until fixpoint or the |
--- |
| 2392 |
/// maximum iteration count is reached. |
--- |
2392 |
/// maximum iteration count is reached. |
--- |
| 2393 |
/// |
--- |
2393 |
/// |
--- |
| 2394 |
/// If the maximum iteration count is reached, This method will |
--- |
2394 |
/// If the maximum iteration count is reached, This method will |
--- |
| 2395 |
/// indicate pessimistic fixpoint on attributes that transitively depend |
--- |
2395 |
/// indicate pessimistic fixpoint on attributes that transitively depend |
--- |
| 2396 |
/// on attributes that were scheduled for an update. |
--- |
2396 |
/// on attributes that were scheduled for an update. |
--- |
| 2397 |
void runTillFixpoint(); |
--- |
2397 |
void runTillFixpoint(); |
--- |
| 2398 |
|
--- |
2398 |
|
--- |
| 2399 |
/// Gets called after scheduling, manifests attributes to the LLVM IR. |
--- |
2399 |
/// Gets called after scheduling, manifests attributes to the LLVM IR. |
--- |
| 2400 |
ChangeStatus manifestAttributes(); |
--- |
2400 |
ChangeStatus manifestAttributes(); |
--- |
| 2401 |
|
--- |
2401 |
|
--- |
| 2402 |
/// Gets called after attributes have been manifested, cleans up the IR. |
--- |
2402 |
/// Gets called after attributes have been manifested, cleans up the IR. |
--- |
| 2403 |
/// Deletes dead functions, blocks and instructions. |
--- |
2403 |
/// Deletes dead functions, blocks and instructions. |
--- |
| 2404 |
/// Rewrites function signitures and updates the call graph. |
--- |
2404 |
/// Rewrites function signitures and updates the call graph. |
--- |
| 2405 |
ChangeStatus cleanupIR(); |
--- |
2405 |
ChangeStatus cleanupIR(); |
--- |
| 2406 |
|
--- |
2406 |
|
--- |
| 2407 |
/// Identify internal functions that are effectively dead, thus not reachable |
--- |
2407 |
/// Identify internal functions that are effectively dead, thus not reachable |
--- |
| 2408 |
/// from a live entry point. The functions are added to ToBeDeletedFunctions. |
--- |
2408 |
/// from a live entry point. The functions are added to ToBeDeletedFunctions. |
--- |
| 2409 |
void identifyDeadInternalFunctions(); |
--- |
2409 |
void identifyDeadInternalFunctions(); |
--- |
| 2410 |
|
--- |
2410 |
|
--- |
| 2411 |
/// Run `::update` on \p AA and track the dependences queried while doing so. |
--- |
2411 |
/// Run `::update` on \p AA and track the dependences queried while doing so. |
--- |
| 2412 |
/// Also adjust the state if we know further updates are not necessary. |
--- |
2412 |
/// Also adjust the state if we know further updates are not necessary. |
--- |
| 2413 |
ChangeStatus updateAA(AbstractAttribute &AA); |
--- |
2413 |
ChangeStatus updateAA(AbstractAttribute &AA); |
--- |
| 2414 |
|
--- |
2414 |
|
--- |
| 2415 |
/// Remember the dependences on the top of the dependence stack such that they |
--- |
2415 |
/// Remember the dependences on the top of the dependence stack such that they |
--- |
| 2416 |
/// may trigger further updates. (\see DependenceStack) |
--- |
2416 |
/// may trigger further updates. (\see DependenceStack) |
--- |
| 2417 |
void rememberDependences(); |
--- |
2417 |
void rememberDependences(); |
--- |
| 2418 |
|
--- |
2418 |
|
--- |
| 2419 |
/// Determine if CallBase context in \p IRP should be propagated. |
--- |
2419 |
/// Determine if CallBase context in \p IRP should be propagated. |
--- |
| 2420 |
bool shouldPropagateCallBaseContext(const IRPosition &IRP); |
--- |
2420 |
bool shouldPropagateCallBaseContext(const IRPosition &IRP); |
--- |
| 2421 |
|
--- |
2421 |
|
--- |
| 2422 |
/// Apply all requested function signature rewrites |
--- |
2422 |
/// Apply all requested function signature rewrites |
--- |
| 2423 |
/// (\see registerFunctionSignatureRewrite) and return Changed if the module |
--- |
2423 |
/// (\see registerFunctionSignatureRewrite) and return Changed if the module |
--- |
| 2424 |
/// was altered. |
--- |
2424 |
/// was altered. |
--- |
| 2425 |
ChangeStatus |
--- |
2425 |
ChangeStatus |
--- |
| 2426 |
rewriteFunctionSignatures(SmallSetVector &ModifiedFns); |
--- |
2426 |
rewriteFunctionSignatures(SmallSetVector &ModifiedFns); |
--- |
| 2427 |
|
--- |
2427 |
|
--- |
| 2428 |
/// Check if the Attribute \p AA should be seeded. |
--- |
2428 |
/// Check if the Attribute \p AA should be seeded. |
--- |
| 2429 |
/// See getOrCreateAAFor. |
--- |
2429 |
/// See getOrCreateAAFor. |
--- |
| 2430 |
bool shouldSeedAttribute(AbstractAttribute &AA); |
--- |
2430 |
bool shouldSeedAttribute(AbstractAttribute &AA); |
--- |
| 2431 |
|
--- |
2431 |
|
--- |
| 2432 |
/// A nested map to lookup abstract attributes based on the argument position |
--- |
2432 |
/// A nested map to lookup abstract attributes based on the argument position |
--- |
| 2433 |
/// on the outer level, and the addresses of the static member (AAType::ID) on |
--- |
2433 |
/// on the outer level, and the addresses of the static member (AAType::ID) on |
--- |
| 2434 |
/// the inner level. |
--- |
2434 |
/// the inner level. |
--- |
| 2435 |
///{ |
--- |
2435 |
///{ |
--- |
| 2436 |
using AAMapKeyTy = std::pair; |
--- |
2436 |
using AAMapKeyTy = std::pair; |
--- |
| 2437 |
DenseMap AAMap; |
--- |
2437 |
DenseMap AAMap; |
--- |
| 2438 |
///} |
--- |
2438 |
///} |
--- |
| 2439 |
|
--- |
2439 |
|
--- |
| 2440 |
/// Map to remember all requested signature changes (= argument replacements). |
--- |
2440 |
/// Map to remember all requested signature changes (= argument replacements). |
--- |
| 2441 |
DenseMap, 8>> |
--- |
2441 |
DenseMap, 8>> |
--- |
| 2442 |
ArgumentReplacementMap; |
--- |
2442 |
ArgumentReplacementMap; |
--- |
| 2443 |
|
--- |
2443 |
|
--- |
| 2444 |
/// The set of functions we are deriving attributes for. |
--- |
2444 |
/// The set of functions we are deriving attributes for. |
--- |
| 2445 |
SetVector &Functions; |
--- |
2445 |
SetVector &Functions; |
--- |
| 2446 |
|
--- |
2446 |
|
--- |
| 2447 |
/// The information cache that holds pre-processed (LLVM-IR) information. |
--- |
2447 |
/// The information cache that holds pre-processed (LLVM-IR) information. |
--- |
| 2448 |
InformationCache &InfoCache; |
--- |
2448 |
InformationCache &InfoCache; |
--- |
| 2449 |
|
--- |
2449 |
|
--- |
| 2450 |
/// Abstract Attribute dependency graph |
--- |
2450 |
/// Abstract Attribute dependency graph |
--- |
| 2451 |
AADepGraph DG; |
--- |
2451 |
AADepGraph DG; |
--- |
| 2452 |
|
--- |
2452 |
|
--- |
| 2453 |
/// Set of functions for which we modified the content such that it might |
--- |
2453 |
/// Set of functions for which we modified the content such that it might |
--- |
| 2454 |
/// impact the call graph. |
--- |
2454 |
/// impact the call graph. |
--- |
| 2455 |
SmallSetVector CGModifiedFunctions; |
--- |
2455 |
SmallSetVector CGModifiedFunctions; |
--- |
| 2456 |
|
--- |
2456 |
|
--- |
| 2457 |
/// Information about a dependence. If FromAA is changed ToAA needs to be |
--- |
2457 |
/// Information about a dependence. If FromAA is changed ToAA needs to be |
--- |
| 2458 |
/// updated as well. |
--- |
2458 |
/// updated as well. |
--- |
| 2459 |
struct DepInfo { |
--- |
2459 |
struct DepInfo { |
--- |
| 2460 |
const AbstractAttribute *FromAA; |
--- |
2460 |
const AbstractAttribute *FromAA; |
--- |
| 2461 |
const AbstractAttribute *ToAA; |
--- |
2461 |
const AbstractAttribute *ToAA; |
--- |
| 2462 |
DepClassTy DepClass; |
--- |
2462 |
DepClassTy DepClass; |
--- |
| 2463 |
}; |
--- |
2463 |
}; |
--- |
| 2464 |
|
--- |
2464 |
|
--- |
| 2465 |
/// The dependence stack is used to track dependences during an |
--- |
2465 |
/// The dependence stack is used to track dependences during an |
--- |
| 2466 |
/// `AbstractAttribute::update` call. As `AbstractAttribute::update` can be |
--- |
2466 |
/// `AbstractAttribute::update` call. As `AbstractAttribute::update` can be |
--- |
| 2467 |
/// recursive we might have multiple vectors of dependences in here. The stack |
--- |
2467 |
/// recursive we might have multiple vectors of dependences in here. The stack |
--- |
| 2468 |
/// size, should be adjusted according to the expected recursion depth and the |
--- |
2468 |
/// size, should be adjusted according to the expected recursion depth and the |
--- |
| 2469 |
/// inner dependence vector size to the expected number of dependences per |
--- |
2469 |
/// inner dependence vector size to the expected number of dependences per |
--- |
| 2470 |
/// abstract attribute. Since the inner vectors are actually allocated on the |
--- |
2470 |
/// abstract attribute. Since the inner vectors are actually allocated on the |
--- |
| 2471 |
/// stack we can be generous with their size. |
--- |
2471 |
/// stack we can be generous with their size. |
--- |
| 2472 |
using DependenceVector = SmallVector; |
--- |
2472 |
using DependenceVector = SmallVector; |
--- |
| 2473 |
SmallVector DependenceStack; |
--- |
2473 |
SmallVector DependenceStack; |
--- |
| 2474 |
|
--- |
2474 |
|
--- |
| 2475 |
/// A set to remember the functions we already assume to be live and visited. |
--- |
2475 |
/// A set to remember the functions we already assume to be live and visited. |
--- |
| 2476 |
DenseSet VisitedFunctions; |
--- |
2476 |
DenseSet VisitedFunctions; |
--- |
| 2477 |
|
--- |
2477 |
|
--- |
| 2478 |
/// Uses we replace with a new value after manifest is done. We will remove |
--- |
2478 |
/// Uses we replace with a new value after manifest is done. We will remove |
--- |
| 2479 |
/// then trivially dead instructions as well. |
--- |
2479 |
/// then trivially dead instructions as well. |
--- |
| 2480 |
SmallMapVector |
--- |
2480 |
SmallMapVector |
--- |
| 2481 |
|
--- |
2481 |
|
--- |
| 2482 |
/// Values we replace with a new value after manifest is done. We will remove |
--- |
2482 |
/// Values we replace with a new value after manifest is done. We will remove |
--- |
| 2483 |
/// then trivially dead instructions as well. |
--- |
2483 |
/// then trivially dead instructions as well. |
--- |
| 2484 |
SmallMapVector, 32> |
--- |
2484 |
SmallMapVector, 32> |
--- |
| 2485 |
ToBeChangedValues; |
--- |
2485 |
ToBeChangedValues; |
--- |
| 2486 |
|
--- |
2486 |
|
--- |
| 2487 |
/// Instructions we replace with `unreachable` insts after manifest is done. |
--- |
2487 |
/// Instructions we replace with `unreachable` insts after manifest is done. |
--- |
| 2488 |
SmallSetVector ToBeChangedToUnreachableInsts; |
--- |
2488 |
SmallSetVector ToBeChangedToUnreachableInsts; |
--- |
| 2489 |
|
--- |
2489 |
|
--- |
| 2490 |
/// Invoke instructions with at least a single dead successor block. |
--- |
2490 |
/// Invoke instructions with at least a single dead successor block. |
--- |
| 2491 |
SmallSetVector InvokeWithDeadSuccessor; |
--- |
2491 |
SmallSetVector InvokeWithDeadSuccessor; |
--- |
| 2492 |
|
--- |
2492 |
|
--- |
| 2493 |
/// A flag that indicates which stage of the process we are in. Initially, the |
--- |
2493 |
/// A flag that indicates which stage of the process we are in. Initially, the |
--- |
| 2494 |
/// phase is SEEDING. Phase is changed in `Attributor::run()` |
--- |
2494 |
/// phase is SEEDING. Phase is changed in `Attributor::run()` |
--- |
| 2495 |
enum class AttributorPhase { |
--- |
2495 |
enum class AttributorPhase { |
--- |
| 2496 |
SEEDING, |
--- |
2496 |
SEEDING, |
--- |
| 2497 |
UPDATE, |
--- |
2497 |
UPDATE, |
--- |
| 2498 |
MANIFEST, |
--- |
2498 |
MANIFEST, |
--- |
| 2499 |
CLEANUP, |
--- |
2499 |
CLEANUP, |
--- |
| 2500 |
} Phase = AttributorPhase::SEEDING; |
--- |
2500 |
} Phase = AttributorPhase::SEEDING; |
--- |
| 2501 |
|
--- |
2501 |
|
--- |
| 2502 |
/// The current initialization chain length. Tracked to avoid stack overflows. |
--- |
2502 |
/// The current initialization chain length. Tracked to avoid stack overflows. |
--- |
| 2503 |
unsigned InitializationChainLength = 0; |
--- |
2503 |
unsigned InitializationChainLength = 0; |
--- |
| 2504 |
|
--- |
2504 |
|
--- |
| 2505 |
/// Functions, blocks, and instructions we delete after manifest is done. |
--- |
2505 |
/// Functions, blocks, and instructions we delete after manifest is done. |
--- |
| 2506 |
/// |
--- |
2506 |
/// |
--- |
| 2507 |
///{ |
--- |
2507 |
///{ |
--- |
| 2508 |
SmallPtrSet ManifestAddedBlocks; |
--- |
2508 |
SmallPtrSet ManifestAddedBlocks; |
--- |
| 2509 |
SmallSetVector ToBeDeletedFunctions; |
--- |
2509 |
SmallSetVector ToBeDeletedFunctions; |
--- |
| 2510 |
SmallSetVector ToBeDeletedBlocks; |
--- |
2510 |
SmallSetVector ToBeDeletedBlocks; |
--- |
| 2511 |
SmallSetVector ToBeDeletedInsts; |
--- |
2511 |
SmallSetVector ToBeDeletedInsts; |
--- |
| 2512 |
///} |
--- |
2512 |
///} |
--- |
| 2513 |
|
--- |
2513 |
|
--- |
| 2514 |
/// Container with all the query AAs that requested an update via |
--- |
2514 |
/// Container with all the query AAs that requested an update via |
--- |
| 2515 |
/// registerForUpdate. |
--- |
2515 |
/// registerForUpdate. |
--- |
| 2516 |
SmallSetVector QueryAAsAwaitingUpdate; |
--- |
2516 |
SmallSetVector QueryAAsAwaitingUpdate; |
--- |
| 2517 |
|
--- |
2517 |
|
--- |
| 2518 |
/// User provided configuration for this Attributor instance. |
--- |
2518 |
/// User provided configuration for this Attributor instance. |
--- |
| 2519 |
const AttributorConfig Configuration; |
--- |
2519 |
const AttributorConfig Configuration; |
--- |
| 2520 |
|
--- |
2520 |
|
--- |
| 2521 |
friend AADepGraph; |
--- |
2521 |
friend AADepGraph; |
--- |
| 2522 |
friend AttributorCallGraph; |
--- |
2522 |
friend AttributorCallGraph; |
--- |
| 2523 |
}; |
--- |
2523 |
}; |
--- |
| 2524 |
|
--- |
2524 |
|
--- |
| 2525 |
/// An interface to query the internal state of an abstract attribute. |
--- |
2525 |
/// An interface to query the internal state of an abstract attribute. |
--- |
| 2526 |
/// |
--- |
2526 |
/// |
--- |
| 2527 |
/// The abstract state is a minimal interface that allows the Attributor to |
--- |
2527 |
/// The abstract state is a minimal interface that allows the Attributor to |
--- |
| 2528 |
/// communicate with the abstract attributes about their internal state without |
--- |
2528 |
/// communicate with the abstract attributes about their internal state without |
--- |
| 2529 |
/// enforcing or exposing implementation details, e.g., the (existence of an) |
--- |
2529 |
/// enforcing or exposing implementation details, e.g., the (existence of an) |
--- |
| 2530 |
/// underlying lattice. |
--- |
2530 |
/// underlying lattice. |
--- |
| 2531 |
/// |
--- |
2531 |
/// |
--- |
| 2532 |
/// It is sufficient to be able to query if a state is (1) valid or invalid, (2) |
--- |
2532 |
/// It is sufficient to be able to query if a state is (1) valid or invalid, (2) |
--- |
| 2533 |
/// at a fixpoint, and to indicate to the state that (3) an optimistic fixpoint |
--- |
2533 |
/// at a fixpoint, and to indicate to the state that (3) an optimistic fixpoint |
--- |
| 2534 |
/// was reached or (4) a pessimistic fixpoint was enforced. |
--- |
2534 |
/// was reached or (4) a pessimistic fixpoint was enforced. |
--- |
| 2535 |
/// |
--- |
2535 |
/// |
--- |
| 2536 |
/// All methods need to be implemented by the subclass. For the common use case, |
--- |
2536 |
/// All methods need to be implemented by the subclass. For the common use case, |
--- |
| 2537 |
/// a single boolean state or a bit-encoded state, the BooleanState and |
--- |
2537 |
/// a single boolean state or a bit-encoded state, the BooleanState and |
--- |
| 2538 |
/// {Inc,Dec,Bit}IntegerState classes are already provided. An abstract |
--- |
2538 |
/// {Inc,Dec,Bit}IntegerState classes are already provided. An abstract |
--- |
| 2539 |
/// attribute can inherit from them to get the abstract state interface and |
--- |
2539 |
/// attribute can inherit from them to get the abstract state interface and |
--- |
| 2540 |
/// additional methods to directly modify the state based if needed. See the |
--- |
2540 |
/// additional methods to directly modify the state based if needed. See the |
--- |
| 2541 |
/// class comments for help. |
--- |
2541 |
/// class comments for help. |
--- |
| 2542 |
struct AbstractState { |
--- |
2542 |
struct AbstractState { |
--- |
| 2543 |
virtual ~AbstractState() = default; |
--- |
2543 |
virtual ~AbstractState() = default; |
--- |
| 2544 |
|
--- |
2544 |
|
--- |
| 2545 |
/// Return if this abstract state is in a valid state. If false, no |
--- |
2545 |
/// Return if this abstract state is in a valid state. If false, no |
--- |
| 2546 |
/// information provided should be used. |
--- |
2546 |
/// information provided should be used. |
--- |
| 2547 |
virtual bool isValidState() const = 0; |
--- |
2547 |
virtual bool isValidState() const = 0; |
--- |
| 2548 |
|
--- |
2548 |
|
--- |
| 2549 |
/// Return if this abstract state is fixed, thus does not need to be updated |
--- |
2549 |
/// Return if this abstract state is fixed, thus does not need to be updated |
--- |
| 2550 |
/// if information changes as it cannot change itself. |
--- |
2550 |
/// if information changes as it cannot change itself. |
--- |
| 2551 |
virtual bool isAtFixpoint() const = 0; |
--- |
2551 |
virtual bool isAtFixpoint() const = 0; |
--- |
| 2552 |
|
--- |
2552 |
|
--- |
| 2553 |
/// Indicate that the abstract state should converge to the optimistic state. |
--- |
2553 |
/// Indicate that the abstract state should converge to the optimistic state. |
--- |
| 2554 |
/// |
--- |
2554 |
/// |
--- |
| 2555 |
/// This will usually make the optimistically assumed state the known to be |
--- |
2555 |
/// This will usually make the optimistically assumed state the known to be |
--- |
| 2556 |
/// true state. |
--- |
2556 |
/// true state. |
--- |
| 2557 |
/// |
--- |
2557 |
/// |
--- |
| 2558 |
/// \returns ChangeStatus::UNCHANGED as the assumed value should not change. |
--- |
2558 |
/// \returns ChangeStatus::UNCHANGED as the assumed value should not change. |
--- |
| 2559 |
virtual ChangeStatus indicateOptimisticFixpoint() = 0; |
--- |
2559 |
virtual ChangeStatus indicateOptimisticFixpoint() = 0; |
--- |
| 2560 |
|
--- |
2560 |
|
--- |
| 2561 |
/// Indicate that the abstract state should converge to the pessimistic state. |
--- |
2561 |
/// Indicate that the abstract state should converge to the pessimistic state. |
--- |
| 2562 |
/// |
--- |
2562 |
/// |
--- |
| 2563 |
/// This will usually revert the optimistically assumed state to the known to |
--- |
2563 |
/// This will usually revert the optimistically assumed state to the known to |
--- |
| 2564 |
/// be true state. |
--- |
2564 |
/// be true state. |
--- |
| 2565 |
/// |
--- |
2565 |
/// |
--- |
| 2566 |
/// \returns ChangeStatus::CHANGED as the assumed value may change. |
--- |
2566 |
/// \returns ChangeStatus::CHANGED as the assumed value may change. |
--- |
| 2567 |
virtual ChangeStatus indicatePessimisticFixpoint() = 0; |
--- |
2567 |
virtual ChangeStatus indicatePessimisticFixpoint() = 0; |
--- |
| 2568 |
}; |
--- |
2568 |
}; |
--- |
| 2569 |
|
--- |
2569 |
|
--- |
| 2570 |
/// Simple state with integers encoding. |
--- |
2570 |
/// Simple state with integers encoding. |
--- |
| 2571 |
/// |
--- |
2571 |
/// |
--- |
| 2572 |
/// The interface ensures that the assumed bits are always a subset of the known |
--- |
2572 |
/// The interface ensures that the assumed bits are always a subset of the known |
--- |
| 2573 |
/// bits. Users can only add known bits and, except through adding known bits, |
--- |
2573 |
/// bits. Users can only add known bits and, except through adding known bits, |
--- |
| 2574 |
/// they can only remove assumed bits. This should guarantee monotonicity and |
--- |
2574 |
/// they can only remove assumed bits. This should guarantee monotonicity and |
--- |
| 2575 |
/// thereby the existence of a fixpoint (if used correctly). The fixpoint is |
--- |
2575 |
/// thereby the existence of a fixpoint (if used correctly). The fixpoint is |
--- |
| 2576 |
/// reached when the assumed and known state/bits are equal. Users can |
--- |
2576 |
/// reached when the assumed and known state/bits are equal. Users can |
--- |
| 2577 |
/// force/inidicate a fixpoint. If an optimistic one is indicated, the known |
--- |
2577 |
/// force/inidicate a fixpoint. If an optimistic one is indicated, the known |
--- |
| 2578 |
/// state will catch up with the assumed one, for a pessimistic fixpoint it is |
--- |
2578 |
/// state will catch up with the assumed one, for a pessimistic fixpoint it is |
--- |
| 2579 |
/// the other way around. |
--- |
2579 |
/// the other way around. |
--- |
| 2580 |
template |
--- |
2580 |
template |
--- |
| 2581 |
struct IntegerStateBase : public AbstractState { |
--- |
2581 |
struct IntegerStateBase : public AbstractState { |
--- |
| 2582 |
using base_t = base_ty; |
--- |
2582 |
using base_t = base_ty; |
--- |
| 2583 |
|
--- |
2583 |
|
--- |
| 2584 |
IntegerStateBase() = default; |
--- |
2584 |
IntegerStateBase() = default; |
--- |
| 2585 |
IntegerStateBase(base_t Assumed) : Assumed(Assumed) {} |
--- |
2585 |
IntegerStateBase(base_t Assumed) : Assumed(Assumed) {} |
--- |
| 2586 |
|
--- |
2586 |
|
--- |
| 2587 |
/// Return the best possible representable state. |
--- |
2587 |
/// Return the best possible representable state. |
--- |
| 2588 |
static constexpr base_t getBestState() { return BestState; } |
--- |
2588 |
static constexpr base_t getBestState() { return BestState; } |
--- |
| 2589 |
static constexpr base_t getBestState(const IntegerStateBase &) { |
--- |
2589 |
static constexpr base_t getBestState(const IntegerStateBase &) { |
--- |
| 2590 |
return getBestState(); |
--- |
2590 |
return getBestState(); |
--- |
| 2591 |
} |
--- |
2591 |
} |
--- |
| 2592 |
|
--- |
2592 |
|
--- |
| 2593 |
/// Return the worst possible representable state. |
--- |
2593 |
/// Return the worst possible representable state. |
--- |
| 2594 |
static constexpr base_t getWorstState() { return WorstState; } |
--- |
2594 |
static constexpr base_t getWorstState() { return WorstState; } |
--- |
| 2595 |
static constexpr base_t getWorstState(const IntegerStateBase &) { |
--- |
2595 |
static constexpr base_t getWorstState(const IntegerStateBase &) { |
--- |
| 2596 |
return getWorstState(); |
--- |
2596 |
return getWorstState(); |
--- |
| 2597 |
} |
--- |
2597 |
} |
--- |
| 2598 |
|
--- |
2598 |
|
--- |
| 2599 |
/// See AbstractState::isValidState() |
--- |
2599 |
/// See AbstractState::isValidState() |
--- |
| 2600 |
/// NOTE: For now we simply pretend that the worst possible state is invalid. |
--- |
2600 |
/// NOTE: For now we simply pretend that the worst possible state is invalid. |
--- |
| 2601 |
bool isValidState() const override { return Assumed != getWorstState(); } |
--- |
2601 |
bool isValidState() const override { return Assumed != getWorstState(); } |
--- |
| 2602 |
|
--- |
2602 |
|
--- |
| 2603 |
/// See AbstractState::isAtFixpoint() |
--- |
2603 |
/// See AbstractState::isAtFixpoint() |
--- |
| 2604 |
bool isAtFixpoint() const override { return Assumed == Known; } |
--- |
2604 |
bool isAtFixpoint() const override { return Assumed == Known; } |
--- |
| 2605 |
|
--- |
2605 |
|
--- |
| 2606 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
2606 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
| 2607 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
2607 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
| 2608 |
Known = Assumed; |
--- |
2608 |
Known = Assumed; |
--- |
| 2609 |
return ChangeStatus::UNCHANGED; |
--- |
2609 |
return ChangeStatus::UNCHANGED; |
--- |
| 2610 |
} |
--- |
2610 |
} |
--- |
| 2611 |
|
--- |
2611 |
|
--- |
| 2612 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
2612 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
| 2613 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
2613 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
| 2614 |
Assumed = Known; |
--- |
2614 |
Assumed = Known; |
--- |
| 2615 |
return ChangeStatus::CHANGED; |
--- |
2615 |
return ChangeStatus::CHANGED; |
--- |
| 2616 |
} |
--- |
2616 |
} |
--- |
| 2617 |
|
--- |
2617 |
|
--- |
| 2618 |
/// Return the known state encoding |
--- |
2618 |
/// Return the known state encoding |
--- |
| 2619 |
base_t getKnown() const { return Known; } |
0 |
2619 |
base_t getKnown() const { return Known; } |
0 |
| 2620 |
|
--- |
2620 |
|
--- |
| 2621 |
/// Return the assumed state encoding. |
--- |
2621 |
/// Return the assumed state encoding. |
--- |
| 2622 |
base_t getAssumed() const { return Assumed; } |
0 |
2622 |
base_t getAssumed() const { return Assumed; } |
0 |
| 2623 |
|
--- |
2623 |
|
--- |
| 2624 |
/// Equality for IntegerStateBase. |
--- |
2624 |
/// Equality for IntegerStateBase. |
--- |
| 2625 |
bool |
--- |
2625 |
bool |
--- |
| 2626 |
operator==(const IntegerStateBase &R) const { |
--- |
2626 |
operator==(const IntegerStateBase &R) const { |
--- |
| 2627 |
return this->getAssumed() == R.getAssumed() && |
--- |
2627 |
return this->getAssumed() == R.getAssumed() && |
--- |
| 2628 |
this->getKnown() == R.getKnown(); |
--- |
2628 |
this->getKnown() == R.getKnown(); |
--- |
| 2629 |
} |
--- |
2629 |
} |
--- |
| 2630 |
|
--- |
2630 |
|
--- |
| 2631 |
/// Inequality for IntegerStateBase. |
--- |
2631 |
/// Inequality for IntegerStateBase. |
--- |
| 2632 |
bool |
--- |
2632 |
bool |
--- |
| 2633 |
operator!=(const IntegerStateBase &R) const { |
--- |
2633 |
operator!=(const IntegerStateBase &R) const { |
--- |
| 2634 |
return !(*this == R); |
--- |
2634 |
return !(*this == R); |
--- |
| 2635 |
} |
--- |
2635 |
} |
--- |
| 2636 |
|
--- |
2636 |
|
--- |
| 2637 |
/// "Clamp" this state with \p R. The result is subtype dependent but it is |
--- |
2637 |
/// "Clamp" this state with \p R. The result is subtype dependent but it is |
--- |
| 2638 |
/// intended that only information assumed in both states will be assumed in |
--- |
2638 |
/// intended that only information assumed in both states will be assumed in |
--- |
| 2639 |
/// this one afterwards. |
--- |
2639 |
/// this one afterwards. |
--- |
| 2640 |
void operator^=(const IntegerStateBase &R) { |
--- |
2640 |
void operator^=(const IntegerStateBase &R) { |
--- |
| 2641 |
handleNewAssumedValue(R.getAssumed()); |
--- |
2641 |
handleNewAssumedValue(R.getAssumed()); |
--- |
| 2642 |
} |
--- |
2642 |
} |
--- |
| 2643 |
|
--- |
2643 |
|
--- |
| 2644 |
/// "Clamp" this state with \p R. The result is subtype dependent but it is |
--- |
2644 |
/// "Clamp" this state with \p R. The result is subtype dependent but it is |
--- |
| 2645 |
/// intended that information known in either state will be known in |
--- |
2645 |
/// intended that information known in either state will be known in |
--- |
| 2646 |
/// this one afterwards. |
--- |
2646 |
/// this one afterwards. |
--- |
| 2647 |
void operator+=(const IntegerStateBase &R) { |
--- |
2647 |
void operator+=(const IntegerStateBase &R) { |
--- |
| 2648 |
handleNewKnownValue(R.getKnown()); |
--- |
2648 |
handleNewKnownValue(R.getKnown()); |
--- |
| 2649 |
} |
--- |
2649 |
} |
--- |
| 2650 |
|
--- |
2650 |
|
--- |
| 2651 |
void operator|=(const IntegerStateBase &R) { |
--- |
2651 |
void operator|=(const IntegerStateBase &R) { |
--- |
| 2652 |
joinOR(R.getAssumed(), R.getKnown()); |
--- |
2652 |
joinOR(R.getAssumed(), R.getKnown()); |
--- |
| 2653 |
} |
--- |
2653 |
} |
--- |
| 2654 |
|
--- |
2654 |
|
--- |
| 2655 |
void operator&=(const IntegerStateBase &R) { |
--- |
2655 |
void operator&=(const IntegerStateBase &R) { |
--- |
| 2656 |
joinAND(R.getAssumed(), R.getKnown()); |
--- |
2656 |
joinAND(R.getAssumed(), R.getKnown()); |
--- |
| 2657 |
} |
--- |
2657 |
} |
--- |
| 2658 |
|
--- |
2658 |
|
--- |
| 2659 |
protected: |
--- |
2659 |
protected: |
--- |
| 2660 |
/// Handle a new assumed value \p Value. Subtype dependent. |
--- |
2660 |
/// Handle a new assumed value \p Value. Subtype dependent. |
--- |
| 2661 |
virtual void handleNewAssumedValue(base_t Value) = 0; |
--- |
2661 |
virtual void handleNewAssumedValue(base_t Value) = 0; |
--- |
| 2662 |
|
--- |
2662 |
|
--- |
| 2663 |
/// Handle a new known value \p Value. Subtype dependent. |
--- |
2663 |
/// Handle a new known value \p Value. Subtype dependent. |
--- |
| 2664 |
virtual void handleNewKnownValue(base_t Value) = 0; |
--- |
2664 |
virtual void handleNewKnownValue(base_t Value) = 0; |
--- |
| 2665 |
|
--- |
2665 |
|
--- |
| 2666 |
/// Handle a value \p Value. Subtype dependent. |
--- |
2666 |
/// Handle a value \p Value. Subtype dependent. |
--- |
| 2667 |
virtual void joinOR(base_t AssumedValue, base_t KnownValue) = 0; |
--- |
2667 |
virtual void joinOR(base_t AssumedValue, base_t KnownValue) = 0; |
--- |
| 2668 |
|
--- |
2668 |
|
--- |
| 2669 |
/// Handle a new assumed value \p Value. Subtype dependent. |
--- |
2669 |
/// Handle a new assumed value \p Value. Subtype dependent. |
--- |
| 2670 |
virtual void joinAND(base_t AssumedValue, base_t KnownValue) = 0; |
--- |
2670 |
virtual void joinAND(base_t AssumedValue, base_t KnownValue) = 0; |
--- |
| 2671 |
|
--- |
2671 |
|
--- |
| 2672 |
/// The known state encoding in an integer of type base_t. |
--- |
2672 |
/// The known state encoding in an integer of type base_t. |
--- |
| 2673 |
base_t Known = getWorstState(); |
--- |
2673 |
base_t Known = getWorstState(); |
--- |
| 2674 |
|
--- |
2674 |
|
--- |
| 2675 |
/// The assumed state encoding in an integer of type base_t. |
--- |
2675 |
/// The assumed state encoding in an integer of type base_t. |
--- |
| 2676 |
base_t Assumed = getBestState(); |
--- |
2676 |
base_t Assumed = getBestState(); |
--- |
| 2677 |
}; |
--- |
2677 |
}; |
--- |
| 2678 |
|
--- |
2678 |
|
--- |
| 2679 |
/// Specialization of the integer state for a bit-wise encoding. |
--- |
2679 |
/// Specialization of the integer state for a bit-wise encoding. |
--- |
| 2680 |
template
| --- |
2680 |
template
| --- |
| |
| 2681 |
base_ty WorstState = 0> |
--- |
2681 |
base_ty WorstState = 0> |
--- |
| 2682 |
struct BitIntegerState |
--- |
2682 |
struct BitIntegerState |
--- |
| 2683 |
: public IntegerStateBase { |
--- |
2683 |
: public IntegerStateBase { |
--- |
| 2684 |
using super = IntegerStateBase; |
--- |
2684 |
using super = IntegerStateBase; |
--- |
| 2685 |
using base_t = base_ty; |
--- |
2685 |
using base_t = base_ty; |
--- |
| 2686 |
BitIntegerState() = default; |
--- |
2686 |
BitIntegerState() = default; |
--- |
| 2687 |
BitIntegerState(base_t Assumed) : super(Assumed) {} |
--- |
2687 |
BitIntegerState(base_t Assumed) : super(Assumed) {} |
--- |
| 2688 |
|
--- |
2688 |
|
--- |
| 2689 |
/// Return true if the bits set in \p BitsEncoding are "known bits". |
--- |
2689 |
/// Return true if the bits set in \p BitsEncoding are "known bits". |
--- |
| 2690 |
bool isKnown(base_t BitsEncoding = BestState) const { |
0 |
2690 |
bool isKnown(base_t BitsEncoding = BestState) const { |
0 |
| 2691 |
return (this->Known & BitsEncoding) == BitsEncoding; |
0 |
2691 |
return (this->Known & BitsEncoding) == BitsEncoding; |
0 |
| 2692 |
} |
--- |
2692 |
} |
--- |
| 2693 |
|
--- |
2693 |
|
--- |
| 2694 |
/// Return true if the bits set in \p BitsEncoding are "assumed bits". |
--- |
2694 |
/// Return true if the bits set in \p BitsEncoding are "assumed bits". |
--- |
| 2695 |
bool isAssumed(base_t BitsEncoding = BestState) const { |
0 |
2695 |
bool isAssumed(base_t BitsEncoding = BestState) const { |
0 |
| 2696 |
return (this->Assumed & BitsEncoding) == BitsEncoding; |
0 |
2696 |
return (this->Assumed & BitsEncoding) == BitsEncoding; |
0 |
| 2697 |
} |
--- |
2697 |
} |
--- |
| 2698 |
|
--- |
2698 |
|
--- |
| 2699 |
/// Add the bits in \p BitsEncoding to the "known bits". |
--- |
2699 |
/// Add the bits in \p BitsEncoding to the "known bits". |
--- |
| 2700 |
BitIntegerState &addKnownBits(base_t Bits) { |
--- |
2700 |
BitIntegerState &addKnownBits(base_t Bits) { |
--- |
| 2701 |
// Make sure we never miss any "known bits". |
--- |
2701 |
// Make sure we never miss any "known bits". |
--- |
| 2702 |
this->Assumed |= Bits; |
--- |
2702 |
this->Assumed |= Bits; |
--- |
| 2703 |
this->Known |= Bits; |
--- |
2703 |
this->Known |= Bits; |
--- |
| 2704 |
return *this; |
--- |
2704 |
return *this; |
--- |
| 2705 |
} |
--- |
2705 |
} |
--- |
| 2706 |
|
--- |
2706 |
|
--- |
| 2707 |
/// Remove the bits in \p BitsEncoding from the "assumed bits" if not known. |
--- |
2707 |
/// Remove the bits in \p BitsEncoding from the "assumed bits" if not known. |
--- |
| 2708 |
BitIntegerState &removeAssumedBits(base_t BitsEncoding) { |
--- |
2708 |
BitIntegerState &removeAssumedBits(base_t BitsEncoding) { |
--- |
| 2709 |
return intersectAssumedBits(~BitsEncoding); |
--- |
2709 |
return intersectAssumedBits(~BitsEncoding); |
--- |
| 2710 |
} |
--- |
2710 |
} |
--- |
| 2711 |
|
--- |
2711 |
|
--- |
| 2712 |
/// Remove the bits in \p BitsEncoding from the "known bits". |
--- |
2712 |
/// Remove the bits in \p BitsEncoding from the "known bits". |
--- |
| 2713 |
BitIntegerState &removeKnownBits(base_t BitsEncoding) { |
--- |
2713 |
BitIntegerState &removeKnownBits(base_t BitsEncoding) { |
--- |
| 2714 |
this->Known = (this->Known & ~BitsEncoding); |
--- |
2714 |
this->Known = (this->Known & ~BitsEncoding); |
--- |
| 2715 |
return *this; |
--- |
2715 |
return *this; |
--- |
| 2716 |
} |
--- |
2716 |
} |
--- |
| 2717 |
|
--- |
2717 |
|
--- |
| 2718 |
/// Keep only "assumed bits" also set in \p BitsEncoding but all known ones. |
--- |
2718 |
/// Keep only "assumed bits" also set in \p BitsEncoding but all known ones. |
--- |
| 2719 |
BitIntegerState &intersectAssumedBits(base_t BitsEncoding) { |
--- |
2719 |
BitIntegerState &intersectAssumedBits(base_t BitsEncoding) { |
--- |
| 2720 |
// Make sure we never lose any "known bits". |
--- |
2720 |
// Make sure we never lose any "known bits". |
--- |
| 2721 |
this->Assumed = (this->Assumed & BitsEncoding) | this->Known; |
--- |
2721 |
this->Assumed = (this->Assumed & BitsEncoding) | this->Known; |
--- |
| 2722 |
return *this; |
--- |
2722 |
return *this; |
--- |
| 2723 |
} |
--- |
2723 |
} |
--- |
| 2724 |
|
--- |
2724 |
|
--- |
| 2725 |
private: |
--- |
2725 |
private: |
--- |
| 2726 |
void handleNewAssumedValue(base_t Value) override { |
--- |
2726 |
void handleNewAssumedValue(base_t Value) override { |
--- |
| 2727 |
intersectAssumedBits(Value); |
--- |
2727 |
intersectAssumedBits(Value); |
--- |
| 2728 |
} |
--- |
2728 |
} |
--- |
| 2729 |
void handleNewKnownValue(base_t Value) override { addKnownBits(Value); } |
--- |
2729 |
void handleNewKnownValue(base_t Value) override { addKnownBits(Value); } |
--- |
| 2730 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
2730 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2731 |
this->Known |= KnownValue; |
--- |
2731 |
this->Known |= KnownValue; |
--- |
| 2732 |
this->Assumed |= AssumedValue; |
--- |
2732 |
this->Assumed |= AssumedValue; |
--- |
| 2733 |
} |
--- |
2733 |
} |
--- |
| 2734 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
2734 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2735 |
this->Known &= KnownValue; |
--- |
2735 |
this->Known &= KnownValue; |
--- |
| 2736 |
this->Assumed &= AssumedValue; |
--- |
2736 |
this->Assumed &= AssumedValue; |
--- |
| 2737 |
} |
--- |
2737 |
} |
--- |
| 2738 |
}; |
--- |
2738 |
}; |
--- |
| 2739 |
|
--- |
2739 |
|
--- |
| 2740 |
/// Specialization of the integer state for an increasing value, hence ~0u is |
--- |
2740 |
/// Specialization of the integer state for an increasing value, hence ~0u is |
--- |
| 2741 |
/// the best state and 0 the worst. |
--- |
2741 |
/// the best state and 0 the worst. |
--- |
| 2742 |
template
| --- |
2742 |
template
| --- |
| |
| 2743 |
base_ty WorstState = 0> |
--- |
2743 |
base_ty WorstState = 0> |
--- |
| 2744 |
struct IncIntegerState |
--- |
2744 |
struct IncIntegerState |
--- |
| 2745 |
: public IntegerStateBase { |
--- |
2745 |
: public IntegerStateBase { |
--- |
| 2746 |
using super = IntegerStateBase; |
--- |
2746 |
using super = IntegerStateBase; |
--- |
| 2747 |
using base_t = base_ty; |
--- |
2747 |
using base_t = base_ty; |
--- |
| 2748 |
|
--- |
2748 |
|
--- |
| 2749 |
IncIntegerState() : super() {} |
--- |
2749 |
IncIntegerState() : super() {} |
--- |
| 2750 |
IncIntegerState(base_t Assumed) : super(Assumed) {} |
--- |
2750 |
IncIntegerState(base_t Assumed) : super(Assumed) {} |
--- |
| 2751 |
|
--- |
2751 |
|
--- |
| 2752 |
/// Return the best possible representable state. |
--- |
2752 |
/// Return the best possible representable state. |
--- |
| 2753 |
static constexpr base_t getBestState() { return BestState; } |
--- |
2753 |
static constexpr base_t getBestState() { return BestState; } |
--- |
| 2754 |
static constexpr base_t |
--- |
2754 |
static constexpr base_t |
--- |
| 2755 |
getBestState(const IncIntegerState &) { |
--- |
2755 |
getBestState(const IncIntegerState &) { |
--- |
| 2756 |
return getBestState(); |
--- |
2756 |
return getBestState(); |
--- |
| 2757 |
} |
--- |
2757 |
} |
--- |
| 2758 |
|
--- |
2758 |
|
--- |
| 2759 |
/// Take minimum of assumed and \p Value. |
--- |
2759 |
/// Take minimum of assumed and \p Value. |
--- |
| 2760 |
IncIntegerState &takeAssumedMinimum(base_t Value) { |
--- |
2760 |
IncIntegerState &takeAssumedMinimum(base_t Value) { |
--- |
| 2761 |
// Make sure we never lose "known value". |
--- |
2761 |
// Make sure we never lose "known value". |
--- |
| 2762 |
this->Assumed = std::max(std::min(this->Assumed, Value), this->Known); |
--- |
2762 |
this->Assumed = std::max(std::min(this->Assumed, Value), this->Known); |
--- |
| 2763 |
return *this; |
--- |
2763 |
return *this; |
--- |
| 2764 |
} |
--- |
2764 |
} |
--- |
| 2765 |
|
--- |
2765 |
|
--- |
| 2766 |
/// Take maximum of known and \p Value. |
--- |
2766 |
/// Take maximum of known and \p Value. |
--- |
| 2767 |
IncIntegerState &takeKnownMaximum(base_t Value) { |
--- |
2767 |
IncIntegerState &takeKnownMaximum(base_t Value) { |
--- |
| 2768 |
// Make sure we never lose "known value". |
--- |
2768 |
// Make sure we never lose "known value". |
--- |
| 2769 |
this->Assumed = std::max(Value, this->Assumed); |
--- |
2769 |
this->Assumed = std::max(Value, this->Assumed); |
--- |
| 2770 |
this->Known = std::max(Value, this->Known); |
--- |
2770 |
this->Known = std::max(Value, this->Known); |
--- |
| 2771 |
return *this; |
--- |
2771 |
return *this; |
--- |
| 2772 |
} |
--- |
2772 |
} |
--- |
| 2773 |
|
--- |
2773 |
|
--- |
| 2774 |
private: |
--- |
2774 |
private: |
--- |
| 2775 |
void handleNewAssumedValue(base_t Value) override { |
--- |
2775 |
void handleNewAssumedValue(base_t Value) override { |
--- |
| 2776 |
takeAssumedMinimum(Value); |
--- |
2776 |
takeAssumedMinimum(Value); |
--- |
| 2777 |
} |
--- |
2777 |
} |
--- |
| 2778 |
void handleNewKnownValue(base_t Value) override { takeKnownMaximum(Value); } |
--- |
2778 |
void handleNewKnownValue(base_t Value) override { takeKnownMaximum(Value); } |
--- |
| 2779 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
2779 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2780 |
this->Known = std::max(this->Known, KnownValue); |
--- |
2780 |
this->Known = std::max(this->Known, KnownValue); |
--- |
| 2781 |
this->Assumed = std::max(this->Assumed, AssumedValue); |
--- |
2781 |
this->Assumed = std::max(this->Assumed, AssumedValue); |
--- |
| 2782 |
} |
--- |
2782 |
} |
--- |
| 2783 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
2783 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2784 |
this->Known = std::min(this->Known, KnownValue); |
--- |
2784 |
this->Known = std::min(this->Known, KnownValue); |
--- |
| 2785 |
this->Assumed = std::min(this->Assumed, AssumedValue); |
--- |
2785 |
this->Assumed = std::min(this->Assumed, AssumedValue); |
--- |
| 2786 |
} |
--- |
2786 |
} |
--- |
| 2787 |
}; |
--- |
2787 |
}; |
--- |
| 2788 |
|
--- |
2788 |
|
--- |
| 2789 |
/// Specialization of the integer state for a decreasing value, hence 0 is the |
--- |
2789 |
/// Specialization of the integer state for a decreasing value, hence 0 is the |
--- |
| 2790 |
/// best state and ~0u the worst. |
--- |
2790 |
/// best state and ~0u the worst. |
--- |
| 2791 |
template |
--- |
2791 |
template |
--- |
| 2792 |
struct DecIntegerState : public IntegerStateBase { |
--- |
2792 |
struct DecIntegerState : public IntegerStateBase { |
--- |
| 2793 |
using base_t = base_ty; |
--- |
2793 |
using base_t = base_ty; |
--- |
| 2794 |
|
--- |
2794 |
|
--- |
| 2795 |
/// Take maximum of assumed and \p Value. |
--- |
2795 |
/// Take maximum of assumed and \p Value. |
--- |
| 2796 |
DecIntegerState &takeAssumedMaximum(base_t Value) { |
--- |
2796 |
DecIntegerState &takeAssumedMaximum(base_t Value) { |
--- |
| 2797 |
// Make sure we never lose "known value". |
--- |
2797 |
// Make sure we never lose "known value". |
--- |
| 2798 |
this->Assumed = std::min(std::max(this->Assumed, Value), this->Known); |
--- |
2798 |
this->Assumed = std::min(std::max(this->Assumed, Value), this->Known); |
--- |
| 2799 |
return *this; |
--- |
2799 |
return *this; |
--- |
| 2800 |
} |
--- |
2800 |
} |
--- |
| 2801 |
|
--- |
2801 |
|
--- |
| 2802 |
/// Take minimum of known and \p Value. |
--- |
2802 |
/// Take minimum of known and \p Value. |
--- |
| 2803 |
DecIntegerState &takeKnownMinimum(base_t Value) { |
--- |
2803 |
DecIntegerState &takeKnownMinimum(base_t Value) { |
--- |
| 2804 |
// Make sure we never lose "known value". |
--- |
2804 |
// Make sure we never lose "known value". |
--- |
| 2805 |
this->Assumed = std::min(Value, this->Assumed); |
--- |
2805 |
this->Assumed = std::min(Value, this->Assumed); |
--- |
| 2806 |
this->Known = std::min(Value, this->Known); |
--- |
2806 |
this->Known = std::min(Value, this->Known); |
--- |
| 2807 |
return *this; |
--- |
2807 |
return *this; |
--- |
| 2808 |
} |
--- |
2808 |
} |
--- |
| 2809 |
|
--- |
2809 |
|
--- |
| 2810 |
private: |
--- |
2810 |
private: |
--- |
| 2811 |
void handleNewAssumedValue(base_t Value) override { |
--- |
2811 |
void handleNewAssumedValue(base_t Value) override { |
--- |
| 2812 |
takeAssumedMaximum(Value); |
--- |
2812 |
takeAssumedMaximum(Value); |
--- |
| 2813 |
} |
--- |
2813 |
} |
--- |
| 2814 |
void handleNewKnownValue(base_t Value) override { takeKnownMinimum(Value); } |
--- |
2814 |
void handleNewKnownValue(base_t Value) override { takeKnownMinimum(Value); } |
--- |
| 2815 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
2815 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2816 |
this->Assumed = std::min(this->Assumed, KnownValue); |
--- |
2816 |
this->Assumed = std::min(this->Assumed, KnownValue); |
--- |
| 2817 |
this->Assumed = std::min(this->Assumed, AssumedValue); |
--- |
2817 |
this->Assumed = std::min(this->Assumed, AssumedValue); |
--- |
| 2818 |
} |
--- |
2818 |
} |
--- |
| 2819 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
2819 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2820 |
this->Assumed = std::max(this->Assumed, KnownValue); |
--- |
2820 |
this->Assumed = std::max(this->Assumed, KnownValue); |
--- |
| 2821 |
this->Assumed = std::max(this->Assumed, AssumedValue); |
--- |
2821 |
this->Assumed = std::max(this->Assumed, AssumedValue); |
--- |
| 2822 |
} |
--- |
2822 |
} |
--- |
| 2823 |
}; |
--- |
2823 |
}; |
--- |
| 2824 |
|
--- |
2824 |
|
--- |
| 2825 |
/// Simple wrapper for a single bit (boolean) state. |
--- |
2825 |
/// Simple wrapper for a single bit (boolean) state. |
--- |
| 2826 |
struct BooleanState : public IntegerStateBase { |
--- |
2826 |
struct BooleanState : public IntegerStateBase { |
--- |
| 2827 |
using super = IntegerStateBase; |
--- |
2827 |
using super = IntegerStateBase; |
--- |
| 2828 |
using base_t = IntegerStateBase::base_t; |
--- |
2828 |
using base_t = IntegerStateBase::base_t; |
--- |
| 2829 |
|
--- |
2829 |
|
--- |
| 2830 |
BooleanState() = default; |
--- |
2830 |
BooleanState() = default; |
--- |
| 2831 |
BooleanState(base_t Assumed) : super(Assumed) {} |
--- |
2831 |
BooleanState(base_t Assumed) : super(Assumed) {} |
--- |
| 2832 |
|
--- |
2832 |
|
--- |
| 2833 |
/// Set the assumed value to \p Value but never below the known one. |
--- |
2833 |
/// Set the assumed value to \p Value but never below the known one. |
--- |
| 2834 |
void setAssumed(bool Value) { Assumed &= (Known | Value); } |
--- |
2834 |
void setAssumed(bool Value) { Assumed &= (Known | Value); } |
--- |
| 2835 |
|
--- |
2835 |
|
--- |
| 2836 |
/// Set the known and asssumed value to \p Value. |
--- |
2836 |
/// Set the known and asssumed value to \p Value. |
--- |
| 2837 |
void setKnown(bool Value) { |
--- |
2837 |
void setKnown(bool Value) { |
--- |
| 2838 |
Known |= Value; |
--- |
2838 |
Known |= Value; |
--- |
| 2839 |
Assumed |= Value; |
--- |
2839 |
Assumed |= Value; |
--- |
| 2840 |
} |
--- |
2840 |
} |
--- |
| 2841 |
|
--- |
2841 |
|
--- |
| 2842 |
/// Return true if the state is assumed to hold. |
--- |
2842 |
/// Return true if the state is assumed to hold. |
--- |
| 2843 |
bool isAssumed() const { return getAssumed(); } |
0 |
2843 |
bool isAssumed() const { return getAssumed(); } |
0 |
| 2844 |
|
--- |
2844 |
|
--- |
| 2845 |
/// Return true if the state is known to hold. |
--- |
2845 |
/// Return true if the state is known to hold. |
--- |
| 2846 |
bool isKnown() const { return getKnown(); } |
0 |
2846 |
bool isKnown() const { return getKnown(); } |
0 |
| 2847 |
|
--- |
2847 |
|
--- |
| 2848 |
private: |
--- |
2848 |
private: |
--- |
| 2849 |
void handleNewAssumedValue(base_t Value) override { |
--- |
2849 |
void handleNewAssumedValue(base_t Value) override { |
--- |
| 2850 |
if (!Value) |
--- |
2850 |
if (!Value) |
--- |
| 2851 |
Assumed = Known; |
--- |
2851 |
Assumed = Known; |
--- |
| 2852 |
} |
--- |
2852 |
} |
--- |
| 2853 |
void handleNewKnownValue(base_t Value) override { |
--- |
2853 |
void handleNewKnownValue(base_t Value) override { |
--- |
| 2854 |
if (Value) |
--- |
2854 |
if (Value) |
--- |
| 2855 |
Known = (Assumed = Value); |
--- |
2855 |
Known = (Assumed = Value); |
--- |
| 2856 |
} |
--- |
2856 |
} |
--- |
| 2857 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
2857 |
void joinOR(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2858 |
Known |= KnownValue; |
--- |
2858 |
Known |= KnownValue; |
--- |
| 2859 |
Assumed |= AssumedValue; |
--- |
2859 |
Assumed |= AssumedValue; |
--- |
| 2860 |
} |
--- |
2860 |
} |
--- |
| 2861 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
2861 |
void joinAND(base_t AssumedValue, base_t KnownValue) override { |
--- |
| 2862 |
Known &= KnownValue; |
--- |
2862 |
Known &= KnownValue; |
--- |
| 2863 |
Assumed &= AssumedValue; |
--- |
2863 |
Assumed &= AssumedValue; |
--- |
| 2864 |
} |
--- |
2864 |
} |
--- |
| 2865 |
}; |
--- |
2865 |
}; |
--- |
| 2866 |
|
--- |
2866 |
|
--- |
| 2867 |
/// State for an integer range. |
--- |
2867 |
/// State for an integer range. |
--- |
| 2868 |
struct IntegerRangeState : public AbstractState { |
--- |
2868 |
struct IntegerRangeState : public AbstractState { |
--- |
| 2869 |
|
--- |
2869 |
|
--- |
| 2870 |
/// Bitwidth of the associated value. |
--- |
2870 |
/// Bitwidth of the associated value. |
--- |
| 2871 |
uint32_t BitWidth; |
--- |
2871 |
uint32_t BitWidth; |
--- |
| 2872 |
|
--- |
2872 |
|
--- |
| 2873 |
/// State representing assumed range, initially set to empty. |
--- |
2873 |
/// State representing assumed range, initially set to empty. |
--- |
| 2874 |
ConstantRange Assumed; |
--- |
2874 |
ConstantRange Assumed; |
--- |
| 2875 |
|
--- |
2875 |
|
--- |
| 2876 |
/// State representing known range, initially set to [-inf, inf]. |
--- |
2876 |
/// State representing known range, initially set to [-inf, inf]. |
--- |
| 2877 |
ConstantRange Known; |
--- |
2877 |
ConstantRange Known; |
--- |
| 2878 |
|
--- |
2878 |
|
--- |
| 2879 |
IntegerRangeState(uint32_t BitWidth) |
--- |
2879 |
IntegerRangeState(uint32_t BitWidth) |
--- |
| 2880 |
: BitWidth(BitWidth), Assumed(ConstantRange::getEmpty(BitWidth)), |
--- |
2880 |
: BitWidth(BitWidth), Assumed(ConstantRange::getEmpty(BitWidth)), |
--- |
| 2881 |
Known(ConstantRange::getFull(BitWidth)) {} |
--- |
2881 |
Known(ConstantRange::getFull(BitWidth)) {} |
--- |
| 2882 |
|
--- |
2882 |
|
--- |
| 2883 |
IntegerRangeState(const ConstantRange &CR) |
--- |
2883 |
IntegerRangeState(const ConstantRange &CR) |
--- |
| 2884 |
: BitWidth(CR.getBitWidth()), Assumed(CR), |
--- |
2884 |
: BitWidth(CR.getBitWidth()), Assumed(CR), |
--- |
| 2885 |
Known(getWorstState(CR.getBitWidth())) {} |
--- |
2885 |
Known(getWorstState(CR.getBitWidth())) {} |
--- |
| 2886 |
|
--- |
2886 |
|
--- |
| 2887 |
/// Return the worst possible representable state. |
--- |
2887 |
/// Return the worst possible representable state. |
--- |
| 2888 |
static ConstantRange getWorstState(uint32_t BitWidth) { |
--- |
2888 |
static ConstantRange getWorstState(uint32_t BitWidth) { |
--- |
| 2889 |
return ConstantRange::getFull(BitWidth); |
--- |
2889 |
return ConstantRange::getFull(BitWidth); |
--- |
| 2890 |
} |
--- |
2890 |
} |
--- |
| 2891 |
|
--- |
2891 |
|
--- |
| 2892 |
/// Return the best possible representable state. |
--- |
2892 |
/// Return the best possible representable state. |
--- |
| 2893 |
static ConstantRange getBestState(uint32_t BitWidth) { |
--- |
2893 |
static ConstantRange getBestState(uint32_t BitWidth) { |
--- |
| 2894 |
return ConstantRange::getEmpty(BitWidth); |
--- |
2894 |
return ConstantRange::getEmpty(BitWidth); |
--- |
| 2895 |
} |
--- |
2895 |
} |
--- |
| 2896 |
static ConstantRange getBestState(const IntegerRangeState &IRS) { |
--- |
2896 |
static ConstantRange getBestState(const IntegerRangeState &IRS) { |
--- |
| 2897 |
return getBestState(IRS.getBitWidth()); |
--- |
2897 |
return getBestState(IRS.getBitWidth()); |
--- |
| 2898 |
} |
--- |
2898 |
} |
--- |
| 2899 |
|
--- |
2899 |
|
--- |
| 2900 |
/// Return associated values' bit width. |
--- |
2900 |
/// Return associated values' bit width. |
--- |
| 2901 |
uint32_t getBitWidth() const { return BitWidth; } |
0 |
2901 |
uint32_t getBitWidth() const { return BitWidth; } |
0 |
| 2902 |
|
--- |
2902 |
|
--- |
| 2903 |
/// See AbstractState::isValidState() |
--- |
2903 |
/// See AbstractState::isValidState() |
--- |
| 2904 |
bool isValidState() const override { |
--- |
2904 |
bool isValidState() const override { |
--- |
| 2905 |
return BitWidth > 0 && !Assumed.isFullSet(); |
--- |
2905 |
return BitWidth > 0 && !Assumed.isFullSet(); |
--- |
| 2906 |
} |
--- |
2906 |
} |
--- |
| 2907 |
|
--- |
2907 |
|
--- |
| 2908 |
/// See AbstractState::isAtFixpoint() |
--- |
2908 |
/// See AbstractState::isAtFixpoint() |
--- |
| 2909 |
bool isAtFixpoint() const override { return Assumed == Known; } |
--- |
2909 |
bool isAtFixpoint() const override { return Assumed == Known; } |
--- |
| 2910 |
|
--- |
2910 |
|
--- |
| 2911 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
2911 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
| 2912 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
2912 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
| 2913 |
Known = Assumed; |
--- |
2913 |
Known = Assumed; |
--- |
| 2914 |
return ChangeStatus::CHANGED; |
--- |
2914 |
return ChangeStatus::CHANGED; |
--- |
| 2915 |
} |
--- |
2915 |
} |
--- |
| 2916 |
|
--- |
2916 |
|
--- |
| 2917 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
2917 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
| 2918 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
2918 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
| 2919 |
Assumed = Known; |
--- |
2919 |
Assumed = Known; |
--- |
| 2920 |
return ChangeStatus::CHANGED; |
--- |
2920 |
return ChangeStatus::CHANGED; |
--- |
| 2921 |
} |
--- |
2921 |
} |
--- |
| 2922 |
|
--- |
2922 |
|
--- |
| 2923 |
/// Return the known state encoding |
--- |
2923 |
/// Return the known state encoding |
--- |
| 2924 |
ConstantRange getKnown() const { return Known; } |
0 |
2924 |
ConstantRange getKnown() const { return Known; } |
0 |
| 2925 |
|
--- |
2925 |
|
--- |
| 2926 |
/// Return the assumed state encoding. |
--- |
2926 |
/// Return the assumed state encoding. |
--- |
| 2927 |
ConstantRange getAssumed() const { return Assumed; } |
0 |
2927 |
ConstantRange getAssumed() const { return Assumed; } |
0 |
| 2928 |
|
--- |
2928 |
|
--- |
| 2929 |
/// Unite assumed range with the passed state. |
--- |
2929 |
/// Unite assumed range with the passed state. |
--- |
| 2930 |
void unionAssumed(const ConstantRange &R) { |
--- |
2930 |
void unionAssumed(const ConstantRange &R) { |
--- |
| 2931 |
// Don't lose a known range. |
--- |
2931 |
// Don't lose a known range. |
--- |
| 2932 |
Assumed = Assumed.unionWith(R).intersectWith(Known); |
--- |
2932 |
Assumed = Assumed.unionWith(R).intersectWith(Known); |
--- |
| 2933 |
} |
--- |
2933 |
} |
--- |
| 2934 |
|
--- |
2934 |
|
--- |
| 2935 |
/// See IntegerRangeState::unionAssumed(..). |
--- |
2935 |
/// See IntegerRangeState::unionAssumed(..). |
--- |
| 2936 |
void unionAssumed(const IntegerRangeState &R) { |
--- |
2936 |
void unionAssumed(const IntegerRangeState &R) { |
--- |
| 2937 |
unionAssumed(R.getAssumed()); |
--- |
2937 |
unionAssumed(R.getAssumed()); |
--- |
| 2938 |
} |
--- |
2938 |
} |
--- |
| 2939 |
|
--- |
2939 |
|
--- |
| 2940 |
/// Intersect known range with the passed state. |
--- |
2940 |
/// Intersect known range with the passed state. |
--- |
| 2941 |
void intersectKnown(const ConstantRange &R) { |
--- |
2941 |
void intersectKnown(const ConstantRange &R) { |
--- |
| 2942 |
Assumed = Assumed.intersectWith(R); |
--- |
2942 |
Assumed = Assumed.intersectWith(R); |
--- |
| 2943 |
Known = Known.intersectWith(R); |
--- |
2943 |
Known = Known.intersectWith(R); |
--- |
| 2944 |
} |
--- |
2944 |
} |
--- |
| 2945 |
|
--- |
2945 |
|
--- |
| 2946 |
/// See IntegerRangeState::intersectKnown(..). |
--- |
2946 |
/// See IntegerRangeState::intersectKnown(..). |
--- |
| 2947 |
void intersectKnown(const IntegerRangeState &R) { |
--- |
2947 |
void intersectKnown(const IntegerRangeState &R) { |
--- |
| 2948 |
intersectKnown(R.getKnown()); |
--- |
2948 |
intersectKnown(R.getKnown()); |
--- |
| 2949 |
} |
--- |
2949 |
} |
--- |
| 2950 |
|
--- |
2950 |
|
--- |
| 2951 |
/// Equality for IntegerRangeState. |
--- |
2951 |
/// Equality for IntegerRangeState. |
--- |
| 2952 |
bool operator==(const IntegerRangeState &R) const { |
--- |
2952 |
bool operator==(const IntegerRangeState &R) const { |
--- |
| 2953 |
return getAssumed() == R.getAssumed() && getKnown() == R.getKnown(); |
--- |
2953 |
return getAssumed() == R.getAssumed() && getKnown() == R.getKnown(); |
--- |
| 2954 |
} |
--- |
2954 |
} |
--- |
| 2955 |
|
--- |
2955 |
|
--- |
| 2956 |
/// "Clamp" this state with \p R. The result is subtype dependent but it is |
--- |
2956 |
/// "Clamp" this state with \p R. The result is subtype dependent but it is |
--- |
| 2957 |
/// intended that only information assumed in both states will be assumed in |
--- |
2957 |
/// intended that only information assumed in both states will be assumed in |
--- |
| 2958 |
/// this one afterwards. |
--- |
2958 |
/// this one afterwards. |
--- |
| 2959 |
IntegerRangeState operator^=(const IntegerRangeState &R) { |
--- |
2959 |
IntegerRangeState operator^=(const IntegerRangeState &R) { |
--- |
| 2960 |
// NOTE: `^=` operator seems like `intersect` but in this case, we need to |
--- |
2960 |
// NOTE: `^=` operator seems like `intersect` but in this case, we need to |
--- |
| 2961 |
// take `union`. |
--- |
2961 |
// take `union`. |
--- |
| 2962 |
unionAssumed(R); |
--- |
2962 |
unionAssumed(R); |
--- |
| 2963 |
return *this; |
--- |
2963 |
return *this; |
--- |
| 2964 |
} |
--- |
2964 |
} |
--- |
| 2965 |
|
--- |
2965 |
|
--- |
| 2966 |
IntegerRangeState operator&=(const IntegerRangeState &R) { |
--- |
2966 |
IntegerRangeState operator&=(const IntegerRangeState &R) { |
--- |
| 2967 |
// NOTE: `&=` operator seems like `intersect` but in this case, we need to |
--- |
2967 |
// NOTE: `&=` operator seems like `intersect` but in this case, we need to |
--- |
| 2968 |
// take `union`. |
--- |
2968 |
// take `union`. |
--- |
| 2969 |
Known = Known.unionWith(R.getKnown()); |
--- |
2969 |
Known = Known.unionWith(R.getKnown()); |
--- |
| 2970 |
Assumed = Assumed.unionWith(R.getAssumed()); |
--- |
2970 |
Assumed = Assumed.unionWith(R.getAssumed()); |
--- |
| 2971 |
return *this; |
--- |
2971 |
return *this; |
--- |
| 2972 |
} |
--- |
2972 |
} |
--- |
| 2973 |
}; |
--- |
2973 |
}; |
--- |
| 2974 |
|
--- |
2974 |
|
--- |
| 2975 |
/// Simple state for a set. |
--- |
2975 |
/// Simple state for a set. |
--- |
| 2976 |
/// |
--- |
2976 |
/// |
--- |
| 2977 |
/// This represents a state containing a set of values. The interface supports |
--- |
2977 |
/// This represents a state containing a set of values. The interface supports |
--- |
| 2978 |
/// modelling sets that contain all possible elements. The state's internal |
--- |
2978 |
/// modelling sets that contain all possible elements. The state's internal |
--- |
| 2979 |
/// value is modified using union or intersection operations. |
--- |
2979 |
/// value is modified using union or intersection operations. |
--- |
| 2980 |
template struct SetState : public AbstractState { |
--- |
2980 |
template struct SetState : public AbstractState { |
--- |
| 2981 |
/// A wrapper around a set that has semantics for handling unions and |
--- |
2981 |
/// A wrapper around a set that has semantics for handling unions and |
--- |
| 2982 |
/// intersections with a "universal" set that contains all elements. |
--- |
2982 |
/// intersections with a "universal" set that contains all elements. |
--- |
| 2983 |
struct SetContents { |
--- |
2983 |
struct SetContents { |
--- |
| 2984 |
/// Creates a universal set with no concrete elements or an empty set. |
--- |
2984 |
/// Creates a universal set with no concrete elements or an empty set. |
--- |
| 2985 |
SetContents(bool Universal) : Universal(Universal) {} |
--- |
2985 |
SetContents(bool Universal) : Universal(Universal) {} |
--- |
| 2986 |
|
--- |
2986 |
|
--- |
| 2987 |
/// Creates a non-universal set with concrete values. |
--- |
2987 |
/// Creates a non-universal set with concrete values. |
--- |
| 2988 |
SetContents(const DenseSet &Assumptions) |
--- |
2988 |
SetContents(const DenseSet &Assumptions) |
--- |
| 2989 |
: Universal(false), Set(Assumptions) {} |
--- |
2989 |
: Universal(false), Set(Assumptions) {} |
--- |
| 2990 |
|
--- |
2990 |
|
--- |
| 2991 |
SetContents(bool Universal, const DenseSet &Assumptions) |
--- |
2991 |
SetContents(bool Universal, const DenseSet &Assumptions) |
--- |
| 2992 |
: Universal(Universal), Set(Assumptions) {} |
--- |
2992 |
: Universal(Universal), Set(Assumptions) {} |
--- |
| 2993 |
|
--- |
2993 |
|
--- |
| 2994 |
const DenseSet &getSet() const { return Set; } |
--- |
2994 |
const DenseSet &getSet() const { return Set; } |
--- |
| 2995 |
|
--- |
2995 |
|
--- |
| 2996 |
bool isUniversal() const { return Universal; } |
--- |
2996 |
bool isUniversal() const { return Universal; } |
--- |
| 2997 |
|
--- |
2997 |
|
--- |
| 2998 |
bool empty() const { return Set.empty() && !Universal; } |
--- |
2998 |
bool empty() const { return Set.empty() && !Universal; } |
--- |
| 2999 |
|
--- |
2999 |
|
--- |
| 3000 |
/// Finds A := A ^ B where A or B could be the "Universal" set which |
--- |
3000 |
/// Finds A := A ^ B where A or B could be the "Universal" set which |
--- |
| 3001 |
/// contains every possible attribute. Returns true if changes were made. |
--- |
3001 |
/// contains every possible attribute. Returns true if changes were made. |
--- |
| 3002 |
bool getIntersection(const SetContents &RHS) { |
--- |
3002 |
bool getIntersection(const SetContents &RHS) { |
--- |
| 3003 |
bool IsUniversal = Universal; |
--- |
3003 |
bool IsUniversal = Universal; |
--- |
| 3004 |
unsigned Size = Set.size(); |
--- |
3004 |
unsigned Size = Set.size(); |
--- |
| 3005 |
|
--- |
3005 |
|
--- |
| 3006 |
// A := A ^ U = A |
--- |
3006 |
// A := A ^ U = A |
--- |
| 3007 |
if (RHS.isUniversal()) |
--- |
3007 |
if (RHS.isUniversal()) |
--- |
| 3008 |
return false; |
--- |
3008 |
return false; |
--- |
| 3009 |
|
--- |
3009 |
|
--- |
| 3010 |
// A := U ^ B = B |
--- |
3010 |
// A := U ^ B = B |
--- |
| 3011 |
if (Universal) |
--- |
3011 |
if (Universal) |
--- |
| 3012 |
Set = RHS.getSet(); |
--- |
3012 |
Set = RHS.getSet(); |
--- |
| 3013 |
else |
--- |
3013 |
else |
--- |
| 3014 |
set_intersect(Set, RHS.getSet()); |
--- |
3014 |
set_intersect(Set, RHS.getSet()); |
--- |
| 3015 |
|
--- |
3015 |
|
--- |
| 3016 |
Universal &= RHS.isUniversal(); |
--- |
3016 |
Universal &= RHS.isUniversal(); |
--- |
| 3017 |
return IsUniversal != Universal || Size != Set.size(); |
--- |
3017 |
return IsUniversal != Universal || Size != Set.size(); |
--- |
| 3018 |
} |
--- |
3018 |
} |
--- |
| 3019 |
|
--- |
3019 |
|
--- |
| 3020 |
/// Finds A := A u B where A or B could be the "Universal" set which |
--- |
3020 |
/// Finds A := A u B where A or B could be the "Universal" set which |
--- |
| 3021 |
/// contains every possible attribute. returns true if changes were made. |
--- |
3021 |
/// contains every possible attribute. returns true if changes were made. |
--- |
| 3022 |
bool getUnion(const SetContents &RHS) { |
--- |
3022 |
bool getUnion(const SetContents &RHS) { |
--- |
| 3023 |
bool IsUniversal = Universal; |
--- |
3023 |
bool IsUniversal = Universal; |
--- |
| 3024 |
unsigned Size = Set.size(); |
--- |
3024 |
unsigned Size = Set.size(); |
--- |
| 3025 |
|
--- |
3025 |
|
--- |
| 3026 |
// A := A u U = U = U u B |
--- |
3026 |
// A := A u U = U = U u B |
--- |
| 3027 |
if (!RHS.isUniversal() && !Universal) |
--- |
3027 |
if (!RHS.isUniversal() && !Universal) |
--- |
| 3028 |
set_union(Set, RHS.getSet()); |
--- |
3028 |
set_union(Set, RHS.getSet()); |
--- |
| 3029 |
|
--- |
3029 |
|
--- |
| 3030 |
Universal |= RHS.isUniversal(); |
--- |
3030 |
Universal |= RHS.isUniversal(); |
--- |
| 3031 |
return IsUniversal != Universal || Size != Set.size(); |
--- |
3031 |
return IsUniversal != Universal || Size != Set.size(); |
--- |
| 3032 |
} |
--- |
3032 |
} |
--- |
| 3033 |
|
--- |
3033 |
|
--- |
| 3034 |
private: |
--- |
3034 |
private: |
--- |
| 3035 |
/// Indicates if this set is "universal", containing every possible element. |
--- |
3035 |
/// Indicates if this set is "universal", containing every possible element. |
--- |
| 3036 |
bool Universal; |
--- |
3036 |
bool Universal; |
--- |
| 3037 |
|
--- |
3037 |
|
--- |
| 3038 |
/// The set of currently active assumptions. |
--- |
3038 |
/// The set of currently active assumptions. |
--- |
| 3039 |
DenseSet Set; |
--- |
3039 |
DenseSet Set; |
--- |
| 3040 |
}; |
--- |
3040 |
}; |
--- |
| 3041 |
|
--- |
3041 |
|
--- |
| 3042 |
SetState() : Known(false), Assumed(true), IsAtFixedpoint(false) {} |
--- |
3042 |
SetState() : Known(false), Assumed(true), IsAtFixedpoint(false) {} |
--- |
| 3043 |
|
--- |
3043 |
|
--- |
| 3044 |
/// Initializes the known state with an initial set and initializes the |
--- |
3044 |
/// Initializes the known state with an initial set and initializes the |
--- |
| 3045 |
/// assumed state as universal. |
--- |
3045 |
/// assumed state as universal. |
--- |
| 3046 |
SetState(const DenseSet &Known) |
--- |
3046 |
SetState(const DenseSet &Known) |
--- |
| 3047 |
: Known(Known), Assumed(true), IsAtFixedpoint(false) {} |
--- |
3047 |
: Known(Known), Assumed(true), IsAtFixedpoint(false) {} |
--- |
| 3048 |
|
--- |
3048 |
|
--- |
| 3049 |
/// See AbstractState::isValidState() |
--- |
3049 |
/// See AbstractState::isValidState() |
--- |
| 3050 |
bool isValidState() const override { return !Assumed.empty(); } |
--- |
3050 |
bool isValidState() const override { return !Assumed.empty(); } |
--- |
| 3051 |
|
--- |
3051 |
|
--- |
| 3052 |
/// See AbstractState::isAtFixpoint() |
--- |
3052 |
/// See AbstractState::isAtFixpoint() |
--- |
| 3053 |
bool isAtFixpoint() const override { return IsAtFixedpoint; } |
--- |
3053 |
bool isAtFixpoint() const override { return IsAtFixedpoint; } |
--- |
| 3054 |
|
--- |
3054 |
|
--- |
| 3055 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
3055 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
| 3056 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
3056 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
| 3057 |
IsAtFixedpoint = true; |
--- |
3057 |
IsAtFixedpoint = true; |
--- |
| 3058 |
Known = Assumed; |
--- |
3058 |
Known = Assumed; |
--- |
| 3059 |
return ChangeStatus::UNCHANGED; |
--- |
3059 |
return ChangeStatus::UNCHANGED; |
--- |
| 3060 |
} |
--- |
3060 |
} |
--- |
| 3061 |
|
--- |
3061 |
|
--- |
| 3062 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
3062 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
| 3063 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
3063 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
| 3064 |
IsAtFixedpoint = true; |
--- |
3064 |
IsAtFixedpoint = true; |
--- |
| 3065 |
Assumed = Known; |
--- |
3065 |
Assumed = Known; |
--- |
| 3066 |
return ChangeStatus::CHANGED; |
--- |
3066 |
return ChangeStatus::CHANGED; |
--- |
| 3067 |
} |
--- |
3067 |
} |
--- |
| 3068 |
|
--- |
3068 |
|
--- |
| 3069 |
/// Return the known state encoding. |
--- |
3069 |
/// Return the known state encoding. |
--- |
| 3070 |
const SetContents &getKnown() const { return Known; } |
--- |
3070 |
const SetContents &getKnown() const { return Known; } |
--- |
| 3071 |
|
--- |
3071 |
|
--- |
| 3072 |
/// Return the assumed state encoding. |
--- |
3072 |
/// Return the assumed state encoding. |
--- |
| 3073 |
const SetContents &getAssumed() const { return Assumed; } |
--- |
3073 |
const SetContents &getAssumed() const { return Assumed; } |
--- |
| 3074 |
|
--- |
3074 |
|
--- |
| 3075 |
/// Returns if the set state contains the element. |
--- |
3075 |
/// Returns if the set state contains the element. |
--- |
| 3076 |
bool setContains(const BaseTy &Elem) const { |
--- |
3076 |
bool setContains(const BaseTy &Elem) const { |
--- |
| 3077 |
return Assumed.getSet().contains(Elem) || Known.getSet().contains(Elem); |
--- |
3077 |
return Assumed.getSet().contains(Elem) || Known.getSet().contains(Elem); |
--- |
| 3078 |
} |
--- |
3078 |
} |
--- |
| 3079 |
|
--- |
3079 |
|
--- |
| 3080 |
/// Performs the set intersection between this set and \p RHS. Returns true if |
--- |
3080 |
/// Performs the set intersection between this set and \p RHS. Returns true if |
--- |
| 3081 |
/// changes were made. |
--- |
3081 |
/// changes were made. |
--- |
| 3082 |
bool getIntersection(const SetContents &RHS) { |
--- |
3082 |
bool getIntersection(const SetContents &RHS) { |
--- |
| 3083 |
bool IsUniversal = Assumed.isUniversal(); |
--- |
3083 |
bool IsUniversal = Assumed.isUniversal(); |
--- |
| 3084 |
unsigned SizeBefore = Assumed.getSet().size(); |
--- |
3084 |
unsigned SizeBefore = Assumed.getSet().size(); |
--- |
| 3085 |
|
--- |
3085 |
|
--- |
| 3086 |
// Get intersection and make sure that the known set is still a proper |
--- |
3086 |
// Get intersection and make sure that the known set is still a proper |
--- |
| 3087 |
// subset of the assumed set. A := K u (A ^ R). |
--- |
3087 |
// subset of the assumed set. A := K u (A ^ R). |
--- |
| 3088 |
Assumed.getIntersection(RHS); |
--- |
3088 |
Assumed.getIntersection(RHS); |
--- |
| 3089 |
Assumed.getUnion(Known); |
--- |
3089 |
Assumed.getUnion(Known); |
--- |
| 3090 |
|
--- |
3090 |
|
--- |
| 3091 |
return SizeBefore != Assumed.getSet().size() || |
--- |
3091 |
return SizeBefore != Assumed.getSet().size() || |
--- |
| 3092 |
IsUniversal != Assumed.isUniversal(); |
--- |
3092 |
IsUniversal != Assumed.isUniversal(); |
--- |
| 3093 |
} |
--- |
3093 |
} |
--- |
| 3094 |
|
--- |
3094 |
|
--- |
| 3095 |
/// Performs the set union between this set and \p RHS. Returns true if |
--- |
3095 |
/// Performs the set union between this set and \p RHS. Returns true if |
--- |
| 3096 |
/// changes were made. |
--- |
3096 |
/// changes were made. |
--- |
| 3097 |
bool getUnion(const SetContents &RHS) { return Assumed.getUnion(RHS); } |
--- |
3097 |
bool getUnion(const SetContents &RHS) { return Assumed.getUnion(RHS); } |
--- |
| 3098 |
|
--- |
3098 |
|
--- |
| 3099 |
private: |
--- |
3099 |
private: |
--- |
| 3100 |
/// The set of values known for this state. |
--- |
3100 |
/// The set of values known for this state. |
--- |
| 3101 |
SetContents Known; |
--- |
3101 |
SetContents Known; |
--- |
| 3102 |
|
--- |
3102 |
|
--- |
| 3103 |
/// The set of assumed values for this state. |
--- |
3103 |
/// The set of assumed values for this state. |
--- |
| 3104 |
SetContents Assumed; |
--- |
3104 |
SetContents Assumed; |
--- |
| 3105 |
|
--- |
3105 |
|
--- |
| 3106 |
bool IsAtFixedpoint; |
--- |
3106 |
bool IsAtFixedpoint; |
--- |
| 3107 |
}; |
--- |
3107 |
}; |
--- |
| 3108 |
|
--- |
3108 |
|
--- |
| 3109 |
/// Helper to tie a abstract state implementation to an abstract attribute. |
--- |
3109 |
/// Helper to tie a abstract state implementation to an abstract attribute. |
--- |
| 3110 |
template |
--- |
3110 |
template |
--- |
| 3111 |
struct StateWrapper : public BaseType, public StateTy { |
--- |
3111 |
struct StateWrapper : public BaseType, public StateTy { |
--- |
| 3112 |
/// Provide static access to the type of the state. |
--- |
3112 |
/// Provide static access to the type of the state. |
--- |
| 3113 |
using StateType = StateTy; |
--- |
3113 |
using StateType = StateTy; |
--- |
| 3114 |
|
--- |
3114 |
|
--- |
| 3115 |
StateWrapper(const IRPosition &IRP, Ts... Args) |
--- |
3115 |
StateWrapper(const IRPosition &IRP, Ts... Args) |
--- |
| 3116 |
: BaseType(IRP), StateTy(Args...) {} |
--- |
3116 |
: BaseType(IRP), StateTy(Args...) {} |
--- |
| 3117 |
|
--- |
3117 |
|
--- |
| 3118 |
/// See AbstractAttribute::getState(...). |
--- |
3118 |
/// See AbstractAttribute::getState(...). |
--- |
| 3119 |
StateType &getState() override { return *this; } |
--- |
3119 |
StateType &getState() override { return *this; } |
--- |
| 3120 |
|
--- |
3120 |
|
--- |
| 3121 |
/// See AbstractAttribute::getState(...). |
--- |
3121 |
/// See AbstractAttribute::getState(...). |
--- |
| 3122 |
const StateType &getState() const override { return *this; } |
--- |
3122 |
const StateType &getState() const override { return *this; } |
--- |
| 3123 |
}; |
--- |
3123 |
}; |
--- |
| 3124 |
|
--- |
3124 |
|
--- |
| 3125 |
/// Helper class that provides common functionality to manifest IR attributes. |
--- |
3125 |
/// Helper class that provides common functionality to manifest IR attributes. |
--- |
| 3126 |
template |
--- |
3126 |
template |
--- |
| 3127 |
struct IRAttribute : public BaseType { |
--- |
3127 |
struct IRAttribute : public BaseType { |
--- |
| 3128 |
IRAttribute(const IRPosition &IRP) : BaseType(IRP) {} |
--- |
3128 |
IRAttribute(const IRPosition &IRP) : BaseType(IRP) {} |
--- |
| 3129 |
|
--- |
3129 |
|
--- |
| 3130 |
/// Most boolean IRAttribute AAs don't do anything non-trivial |
--- |
3130 |
/// Most boolean IRAttribute AAs don't do anything non-trivial |
--- |
| 3131 |
/// in their initializers while non-boolean ones often do. Subclasses can |
--- |
3131 |
/// in their initializers while non-boolean ones often do. Subclasses can |
--- |
| 3132 |
/// change this. |
--- |
3132 |
/// change this. |
--- |
| 3133 |
static bool hasTrivialInitializer() { return Attribute::isEnumAttrKind(AK); } |
0 |
3133 |
static bool hasTrivialInitializer() { return Attribute::isEnumAttrKind(AK); } |
0 |
| 3134 |
|
--- |
3134 |
|
--- |
| 3135 |
/// Compile time access to the IR attribute kind. |
--- |
3135 |
/// Compile time access to the IR attribute kind. |
--- |
| 3136 |
static constexpr Attribute::AttrKind IRAttributeKind = AK; |
--- |
3136 |
static constexpr Attribute::AttrKind IRAttributeKind = AK; |
--- |
| 3137 |
|
--- |
3137 |
|
--- |
| 3138 |
/// Return true if the IR attribute(s) associated with this AA are implied for |
--- |
3138 |
/// Return true if the IR attribute(s) associated with this AA are implied for |
--- |
| 3139 |
/// an undef value. |
--- |
3139 |
/// an undef value. |
--- |
| 3140 |
static bool isImpliedByUndef() { return true; } |
0 |
3140 |
static bool isImpliedByUndef() { return true; } |
0 |
| 3141 |
|
--- |
3141 |
|
--- |
| 3142 |
/// Return true if the IR attribute(s) associated with this AA are implied for |
--- |
3142 |
/// Return true if the IR attribute(s) associated with this AA are implied for |
--- |
| 3143 |
/// an poison value. |
--- |
3143 |
/// an poison value. |
--- |
| 3144 |
static bool isImpliedByPoison() { return true; } |
0 |
3144 |
static bool isImpliedByPoison() { return true; } |
0 |
| 3145 |
|
--- |
3145 |
|
--- |
| 3146 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
3146 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 3147 |
Attribute::AttrKind ImpliedAttributeKind = AK, |
--- |
3147 |
Attribute::AttrKind ImpliedAttributeKind = AK, |
--- |
| 3148 |
bool IgnoreSubsumingPositions = false) { |
--- |
3148 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 3149 |
if (AAType::isImpliedByUndef() && isa(IRP.getAssociatedValue())) |
0 |
3149 |
if (AAType::isImpliedByUndef() && isa(IRP.getAssociatedValue())) |
0 |
| 3150 |
return true; |
0 |
3150 |
return true; |
0 |
| 3151 |
if (AAType::isImpliedByPoison() && |
0 |
3151 |
if (AAType::isImpliedByPoison() && |
0 |
| 3152 |
isa(IRP.getAssociatedValue())) |
0 |
3152 |
isa(IRP.getAssociatedValue())) |
0 |
| 3153 |
return true; |
0 |
3153 |
return true; |
0 |
| 3154 |
return A.hasAttr(IRP, {ImpliedAttributeKind}, IgnoreSubsumingPositions, |
0 |
3154 |
return A.hasAttr(IRP, {ImpliedAttributeKind}, IgnoreSubsumingPositions, |
0 |
| 3155 |
ImpliedAttributeKind); |
0 |
3155 |
ImpliedAttributeKind); |
0 |
| 3156 |
} |
--- |
3156 |
} |
--- |
| 3157 |
|
--- |
3157 |
|
--- |
| 3158 |
/// See AbstractAttribute::manifest(...). |
--- |
3158 |
/// See AbstractAttribute::manifest(...). |
--- |
| 3159 |
ChangeStatus manifest(Attributor &A) override { |
--- |
3159 |
ChangeStatus manifest(Attributor &A) override { |
--- |
| 3160 |
if (isa(this->getIRPosition().getAssociatedValue())) |
--- |
3160 |
if (isa(this->getIRPosition().getAssociatedValue())) |
--- |
| 3161 |
return ChangeStatus::UNCHANGED; |
--- |
3161 |
return ChangeStatus::UNCHANGED; |
--- |
| 3162 |
SmallVector DeducedAttrs; |
--- |
3162 |
SmallVector DeducedAttrs; |
--- |
| 3163 |
getDeducedAttributes(A, this->getAnchorValue().getContext(), DeducedAttrs); |
--- |
3163 |
getDeducedAttributes(A, this->getAnchorValue().getContext(), DeducedAttrs); |
--- |
| 3164 |
if (DeducedAttrs.empty()) |
--- |
3164 |
if (DeducedAttrs.empty()) |
--- |
| 3165 |
return ChangeStatus::UNCHANGED; |
--- |
3165 |
return ChangeStatus::UNCHANGED; |
--- |
| 3166 |
return A.manifestAttrs(this->getIRPosition(), DeducedAttrs); |
--- |
3166 |
return A.manifestAttrs(this->getIRPosition(), DeducedAttrs); |
--- |
| 3167 |
} |
--- |
3167 |
} |
--- |
| 3168 |
|
--- |
3168 |
|
--- |
| 3169 |
/// Return the kind that identifies the abstract attribute implementation. |
--- |
3169 |
/// Return the kind that identifies the abstract attribute implementation. |
--- |
| 3170 |
Attribute::AttrKind getAttrKind() const { return AK; } |
--- |
3170 |
Attribute::AttrKind getAttrKind() const { return AK; } |
--- |
| 3171 |
|
--- |
3171 |
|
--- |
| 3172 |
/// Return the deduced attributes in \p Attrs. |
--- |
3172 |
/// Return the deduced attributes in \p Attrs. |
--- |
| 3173 |
virtual void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
--- |
3173 |
virtual void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
--- |
| 3174 |
SmallVectorImpl &Attrs) const { |
--- |
3174 |
SmallVectorImpl &Attrs) const { |
--- |
| 3175 |
Attrs.emplace_back(Attribute::get(Ctx, getAttrKind())); |
--- |
3175 |
Attrs.emplace_back(Attribute::get(Ctx, getAttrKind())); |
--- |
| 3176 |
} |
--- |
3176 |
} |
--- |
| 3177 |
}; |
--- |
3177 |
}; |
--- |
| 3178 |
|
--- |
3178 |
|
--- |
| 3179 |
/// Base struct for all "concrete attribute" deductions. |
--- |
3179 |
/// Base struct for all "concrete attribute" deductions. |
--- |
| 3180 |
/// |
--- |
3180 |
/// |
--- |
| 3181 |
/// The abstract attribute is a minimal interface that allows the Attributor to |
--- |
3181 |
/// The abstract attribute is a minimal interface that allows the Attributor to |
--- |
| 3182 |
/// orchestrate the abstract/fixpoint analysis. The design allows to hide away |
--- |
3182 |
/// orchestrate the abstract/fixpoint analysis. The design allows to hide away |
--- |
| 3183 |
/// implementation choices made for the subclasses but also to structure their |
--- |
3183 |
/// implementation choices made for the subclasses but also to structure their |
--- |
| 3184 |
/// implementation and simplify the use of other abstract attributes in-flight. |
--- |
3184 |
/// implementation and simplify the use of other abstract attributes in-flight. |
--- |
| 3185 |
/// |
--- |
3185 |
/// |
--- |
| 3186 |
/// To allow easy creation of new attributes, most methods have default |
--- |
3186 |
/// To allow easy creation of new attributes, most methods have default |
--- |
| 3187 |
/// implementations. The ones that do not are generally straight forward, except |
--- |
3187 |
/// implementations. The ones that do not are generally straight forward, except |
--- |
| 3188 |
/// `AbstractAttribute::updateImpl` which is the location of most reasoning |
--- |
3188 |
/// `AbstractAttribute::updateImpl` which is the location of most reasoning |
--- |
| 3189 |
/// associated with the abstract attribute. The update is invoked by the |
--- |
3189 |
/// associated with the abstract attribute. The update is invoked by the |
--- |
| 3190 |
/// Attributor in case the situation used to justify the current optimistic |
--- |
3190 |
/// Attributor in case the situation used to justify the current optimistic |
--- |
| 3191 |
/// state might have changed. The Attributor determines this automatically |
--- |
3191 |
/// state might have changed. The Attributor determines this automatically |
--- |
| 3192 |
/// by monitoring the `Attributor::getAAFor` calls made by abstract attributes. |
--- |
3192 |
/// by monitoring the `Attributor::getAAFor` calls made by abstract attributes. |
--- |
| 3193 |
/// |
--- |
3193 |
/// |
--- |
| 3194 |
/// The `updateImpl` method should inspect the IR and other abstract attributes |
--- |
3194 |
/// The `updateImpl` method should inspect the IR and other abstract attributes |
--- |
| 3195 |
/// in-flight to justify the best possible (=optimistic) state. The actual |
--- |
3195 |
/// in-flight to justify the best possible (=optimistic) state. The actual |
--- |
| 3196 |
/// implementation is, similar to the underlying abstract state encoding, not |
--- |
3196 |
/// implementation is, similar to the underlying abstract state encoding, not |
--- |
| 3197 |
/// exposed. In the most common case, the `updateImpl` will go through a list of |
--- |
3197 |
/// exposed. In the most common case, the `updateImpl` will go through a list of |
--- |
| 3198 |
/// reasons why its optimistic state is valid given the current information. If |
--- |
3198 |
/// reasons why its optimistic state is valid given the current information. If |
--- |
| 3199 |
/// any combination of them holds and is sufficient to justify the current |
--- |
3199 |
/// any combination of them holds and is sufficient to justify the current |
--- |
| 3200 |
/// optimistic state, the method shall return UNCHAGED. If not, the optimistic |
--- |
3200 |
/// optimistic state, the method shall return UNCHAGED. If not, the optimistic |
--- |
| 3201 |
/// state is adjusted to the situation and the method shall return CHANGED. |
--- |
3201 |
/// state is adjusted to the situation and the method shall return CHANGED. |
--- |
| 3202 |
/// |
--- |
3202 |
/// |
--- |
| 3203 |
/// If the manifestation of the "concrete attribute" deduced by the subclass |
--- |
3203 |
/// If the manifestation of the "concrete attribute" deduced by the subclass |
--- |
| 3204 |
/// differs from the "default" behavior, which is a (set of) LLVM-IR |
--- |
3204 |
/// differs from the "default" behavior, which is a (set of) LLVM-IR |
--- |
| 3205 |
/// attribute(s) for an argument, call site argument, function return value, or |
--- |
3205 |
/// attribute(s) for an argument, call site argument, function return value, or |
--- |
| 3206 |
/// function, the `AbstractAttribute::manifest` method should be overloaded. |
--- |
3206 |
/// function, the `AbstractAttribute::manifest` method should be overloaded. |
--- |
| 3207 |
/// |
--- |
3207 |
/// |
--- |
| 3208 |
/// NOTE: If the state obtained via getState() is INVALID, thus if |
--- |
3208 |
/// NOTE: If the state obtained via getState() is INVALID, thus if |
--- |
| 3209 |
/// AbstractAttribute::getState().isValidState() returns false, no |
--- |
3209 |
/// AbstractAttribute::getState().isValidState() returns false, no |
--- |
| 3210 |
/// information provided by the methods of this class should be used. |
--- |
3210 |
/// information provided by the methods of this class should be used. |
--- |
| 3211 |
/// NOTE: The Attributor currently has certain limitations to what we can do. |
--- |
3211 |
/// NOTE: The Attributor currently has certain limitations to what we can do. |
--- |
| 3212 |
/// As a general rule of thumb, "concrete" abstract attributes should *for |
--- |
3212 |
/// As a general rule of thumb, "concrete" abstract attributes should *for |
--- |
| 3213 |
/// now* only perform "backward" information propagation. That means |
--- |
3213 |
/// now* only perform "backward" information propagation. That means |
--- |
| 3214 |
/// optimistic information obtained through abstract attributes should |
--- |
3214 |
/// optimistic information obtained through abstract attributes should |
--- |
| 3215 |
/// only be used at positions that precede the origin of the information |
--- |
3215 |
/// only be used at positions that precede the origin of the information |
--- |
| 3216 |
/// with regards to the program flow. More practically, information can |
--- |
3216 |
/// with regards to the program flow. More practically, information can |
--- |
| 3217 |
/// *now* be propagated from instructions to their enclosing function, but |
--- |
3217 |
/// *now* be propagated from instructions to their enclosing function, but |
--- |
| 3218 |
/// *not* from call sites to the called function. The mechanisms to allow |
--- |
3218 |
/// *not* from call sites to the called function. The mechanisms to allow |
--- |
| 3219 |
/// both directions will be added in the future. |
--- |
3219 |
/// both directions will be added in the future. |
--- |
| 3220 |
/// NOTE: The mechanics of adding a new "concrete" abstract attribute are |
--- |
3220 |
/// NOTE: The mechanics of adding a new "concrete" abstract attribute are |
--- |
| 3221 |
/// described in the file comment. |
--- |
3221 |
/// described in the file comment. |
--- |
| 3222 |
struct AbstractAttribute : public IRPosition, public AADepGraphNode { |
--- |
3222 |
struct AbstractAttribute : public IRPosition, public AADepGraphNode { |
--- |
| 3223 |
using StateType = AbstractState; |
--- |
3223 |
using StateType = AbstractState; |
--- |
| 3224 |
|
--- |
3224 |
|
--- |
| 3225 |
AbstractAttribute(const IRPosition &IRP) : IRPosition(IRP) {} |
--- |
3225 |
AbstractAttribute(const IRPosition &IRP) : IRPosition(IRP) {} |
--- |
| 3226 |
|
--- |
3226 |
|
--- |
| 3227 |
/// Virtual destructor. |
--- |
3227 |
/// Virtual destructor. |
--- |
| 3228 |
virtual ~AbstractAttribute() = default; |
--- |
3228 |
virtual ~AbstractAttribute() = default; |
--- |
| 3229 |
|
--- |
3229 |
|
--- |
| 3230 |
/// This function is used to identify if an \p DGN is of type |
--- |
3230 |
/// This function is used to identify if an \p DGN is of type |
--- |
| 3231 |
/// AbstractAttribute so that the dyn_cast and cast can use such information |
--- |
3231 |
/// AbstractAttribute so that the dyn_cast and cast can use such information |
--- |
| 3232 |
/// to cast an AADepGraphNode to an AbstractAttribute. |
--- |
3232 |
/// to cast an AADepGraphNode to an AbstractAttribute. |
--- |
| 3233 |
/// |
--- |
3233 |
/// |
--- |
| 3234 |
/// We eagerly return true here because all AADepGraphNodes except for the |
--- |
3234 |
/// We eagerly return true here because all AADepGraphNodes except for the |
--- |
| 3235 |
/// Synthethis Node are of type AbstractAttribute |
--- |
3235 |
/// Synthethis Node are of type AbstractAttribute |
--- |
| 3236 |
static bool classof(const AADepGraphNode *DGN) { return true; } |
0 |
3236 |
static bool classof(const AADepGraphNode *DGN) { return true; } |
0 |
| 3237 |
|
--- |
3237 |
|
--- |
| 3238 |
/// Return false if this AA does anything non-trivial (hence not done by |
--- |
3238 |
/// Return false if this AA does anything non-trivial (hence not done by |
--- |
| 3239 |
/// default) in its initializer. |
--- |
3239 |
/// default) in its initializer. |
--- |
| 3240 |
static bool hasTrivialInitializer() { return false; } |
0 |
3240 |
static bool hasTrivialInitializer() { return false; } |
0 |
| 3241 |
|
--- |
3241 |
|
--- |
| 3242 |
/// Return true if this AA requires a "callee" (or an associted function) for |
--- |
3242 |
/// Return true if this AA requires a "callee" (or an associted function) for |
--- |
| 3243 |
/// a call site positon. Default is optimistic to minimize AAs. |
--- |
3243 |
/// a call site positon. Default is optimistic to minimize AAs. |
--- |
| 3244 |
static bool requiresCalleeForCallBase() { return true; } |
0 |
3244 |
static bool requiresCalleeForCallBase() { return true; } |
0 |
| 3245 |
|
--- |
3245 |
|
--- |
| 3246 |
/// Return true if this AA requires all callees for an argument or function |
--- |
3246 |
/// Return true if this AA requires all callees for an argument or function |
--- |
| 3247 |
/// positon. |
--- |
3247 |
/// positon. |
--- |
| 3248 |
static bool requiresCallersForArgOrFunction() { return false; } |
0 |
3248 |
static bool requiresCallersForArgOrFunction() { return false; } |
0 |
| 3249 |
|
--- |
3249 |
|
--- |
| 3250 |
/// Return false if an AA should not be created for \p IRP. |
--- |
3250 |
/// Return false if an AA should not be created for \p IRP. |
--- |
| 3251 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
3251 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 3252 |
return true; |
0 |
3252 |
return true; |
0 |
| 3253 |
} |
--- |
3253 |
} |
--- |
| 3254 |
|
--- |
3254 |
|
--- |
| 3255 |
/// Return false if an AA should not be updated for \p IRP. |
--- |
3255 |
/// Return false if an AA should not be updated for \p IRP. |
--- |
| 3256 |
static bool isValidIRPositionForUpdate(Attributor &A, const IRPosition &IRP) { |
0 |
3256 |
static bool isValidIRPositionForUpdate(Attributor &A, const IRPosition &IRP) { |
0 |
| 3257 |
Function *AssociatedFn = IRP.getAssociatedFunction(); |
0 |
3257 |
Function *AssociatedFn = IRP.getAssociatedFunction(); |
0 |
| 3258 |
bool IsFnInterface = IRP.isFnInterfaceKind(); |
0 |
3258 |
bool IsFnInterface = IRP.isFnInterfaceKind(); |
0 |
| 3259 |
assert((!IsFnInterface || AssociatedFn) && |
0 |
3259 |
assert((!IsFnInterface || AssociatedFn) && |
0 |
| 3260 |
"Function interface without a function?"); |
--- |
3260 |
"Function interface without a function?"); |
--- |
| 3261 |
|
--- |
3261 |
|
--- |
| 3262 |
// TODO: Not all attributes require an exact definition. Find a way to |
--- |
3262 |
// TODO: Not all attributes require an exact definition. Find a way to |
--- |
| 3263 |
// enable deduction for some but not all attributes in case the |
--- |
3263 |
// enable deduction for some but not all attributes in case the |
--- |
| 3264 |
// definition might be changed at runtime, see also |
--- |
3264 |
// definition might be changed at runtime, see also |
--- |
| 3265 |
// http://lists.llvm.org/pipermail/llvm-dev/2018-February/121275.html. |
--- |
3265 |
// http://lists.llvm.org/pipermail/llvm-dev/2018-February/121275.html. |
--- |
| 3266 |
// TODO: We could always determine abstract attributes and if sufficient |
--- |
3266 |
// TODO: We could always determine abstract attributes and if sufficient |
--- |
| 3267 |
// information was found we could duplicate the functions that do not |
--- |
3267 |
// information was found we could duplicate the functions that do not |
--- |
| 3268 |
// have an exact definition. |
--- |
3268 |
// have an exact definition. |
--- |
| 3269 |
return !IsFnInterface || A.isFunctionIPOAmendable(*AssociatedFn); |
0 |
3269 |
return !IsFnInterface || A.isFunctionIPOAmendable(*AssociatedFn); |
0 |
| 3270 |
} |
--- |
3270 |
} |
--- |
| 3271 |
|
--- |
3271 |
|
--- |
| 3272 |
/// Initialize the state with the information in the Attributor \p A. |
--- |
3272 |
/// Initialize the state with the information in the Attributor \p A. |
--- |
| 3273 |
/// |
--- |
3273 |
/// |
--- |
| 3274 |
/// This function is called by the Attributor once all abstract attributes |
--- |
3274 |
/// This function is called by the Attributor once all abstract attributes |
--- |
| 3275 |
/// have been identified. It can and shall be used for task like: |
--- |
3275 |
/// have been identified. It can and shall be used for task like: |
--- |
| 3276 |
/// - identify existing knowledge in the IR and use it for the "known state" |
--- |
3276 |
/// - identify existing knowledge in the IR and use it for the "known state" |
--- |
| 3277 |
/// - perform any work that is not going to change over time, e.g., determine |
--- |
3277 |
/// - perform any work that is not going to change over time, e.g., determine |
--- |
| 3278 |
/// a subset of the IR, or attributes in-flight, that have to be looked at |
--- |
3278 |
/// a subset of the IR, or attributes in-flight, that have to be looked at |
--- |
| 3279 |
/// in the `updateImpl` method. |
--- |
3279 |
/// in the `updateImpl` method. |
--- |
| 3280 |
virtual void initialize(Attributor &A) {} |
0 |
3280 |
virtual void initialize(Attributor &A) {} |
0 |
| 3281 |
|
--- |
3281 |
|
--- |
| 3282 |
/// A query AA is always scheduled as long as we do updates because it does |
--- |
3282 |
/// A query AA is always scheduled as long as we do updates because it does |
--- |
| 3283 |
/// lazy computation that cannot be determined to be done from the outside. |
--- |
3283 |
/// lazy computation that cannot be determined to be done from the outside. |
--- |
| 3284 |
/// However, while query AAs will not be fixed if they do not have outstanding |
--- |
3284 |
/// However, while query AAs will not be fixed if they do not have outstanding |
--- |
| 3285 |
/// dependences, we will only schedule them like other AAs. If a query AA that |
--- |
3285 |
/// dependences, we will only schedule them like other AAs. If a query AA that |
--- |
| 3286 |
/// received a new query it needs to request an update via |
--- |
3286 |
/// received a new query it needs to request an update via |
--- |
| 3287 |
/// `Attributor::requestUpdateForAA`. |
--- |
3287 |
/// `Attributor::requestUpdateForAA`. |
--- |
| 3288 |
virtual bool isQueryAA() const { return false; } |
0 |
3288 |
virtual bool isQueryAA() const { return false; } |
0 |
| 3289 |
|
--- |
3289 |
|
--- |
| 3290 |
/// Return the internal abstract state for inspection. |
--- |
3290 |
/// Return the internal abstract state for inspection. |
--- |
| 3291 |
virtual StateType &getState() = 0; |
--- |
3291 |
virtual StateType &getState() = 0; |
--- |
| 3292 |
virtual const StateType &getState() const = 0; |
--- |
3292 |
virtual const StateType &getState() const = 0; |
--- |
| 3293 |
|
--- |
3293 |
|
--- |
| 3294 |
/// Return an IR position, see struct IRPosition. |
--- |
3294 |
/// Return an IR position, see struct IRPosition. |
--- |
| 3295 |
const IRPosition &getIRPosition() const { return *this; }; |
0 |
3295 |
const IRPosition &getIRPosition() const { return *this; }; |
0 |
| 3296 |
IRPosition &getIRPosition() { return *this; }; |
0 |
3296 |
IRPosition &getIRPosition() { return *this; }; |
0 |
| 3297 |
|
--- |
3297 |
|
--- |
| 3298 |
/// Helper functions, for debug purposes only. |
--- |
3298 |
/// Helper functions, for debug purposes only. |
--- |
| 3299 |
///{ |
--- |
3299 |
///{ |
--- |
| 3300 |
void print(raw_ostream &OS) const { print(nullptr, OS); } |
0 |
3300 |
void print(raw_ostream &OS) const { print(nullptr, OS); } |
0 |
| 3301 |
void print(Attributor *, raw_ostream &OS) const override; |
--- |
3301 |
void print(Attributor *, raw_ostream &OS) const override; |
--- |
| 3302 |
virtual void printWithDeps(raw_ostream &OS) const; |
--- |
3302 |
virtual void printWithDeps(raw_ostream &OS) const; |
--- |
| 3303 |
void dump() const { this->print(dbgs()); } |
--- |
3303 |
void dump() const { this->print(dbgs()); } |
--- |
| 3304 |
|
--- |
3304 |
|
--- |
| 3305 |
/// This function should return the "summarized" assumed state as string. |
--- |
3305 |
/// This function should return the "summarized" assumed state as string. |
--- |
| 3306 |
virtual const std::string getAsStr(Attributor *A) const = 0; |
--- |
3306 |
virtual const std::string getAsStr(Attributor *A) const = 0; |
--- |
| 3307 |
|
--- |
3307 |
|
--- |
| 3308 |
/// This function should return the name of the AbstractAttribute |
--- |
3308 |
/// This function should return the name of the AbstractAttribute |
--- |
| 3309 |
virtual const std::string getName() const = 0; |
--- |
3309 |
virtual const std::string getName() const = 0; |
--- |
| 3310 |
|
--- |
3310 |
|
--- |
| 3311 |
/// This function should return the address of the ID of the AbstractAttribute |
--- |
3311 |
/// This function should return the address of the ID of the AbstractAttribute |
--- |
| 3312 |
virtual const char *getIdAddr() const = 0; |
--- |
3312 |
virtual const char *getIdAddr() const = 0; |
--- |
| 3313 |
///} |
--- |
3313 |
///} |
--- |
| 3314 |
|
--- |
3314 |
|
--- |
| 3315 |
/// Allow the Attributor access to the protected methods. |
--- |
3315 |
/// Allow the Attributor access to the protected methods. |
--- |
| 3316 |
friend struct Attributor; |
--- |
3316 |
friend struct Attributor; |
--- |
| 3317 |
|
--- |
3317 |
|
--- |
| 3318 |
protected: |
--- |
3318 |
protected: |
--- |
| 3319 |
/// Hook for the Attributor to trigger an update of the internal state. |
--- |
3319 |
/// Hook for the Attributor to trigger an update of the internal state. |
--- |
| 3320 |
/// |
--- |
3320 |
/// |
--- |
| 3321 |
/// If this attribute is already fixed, this method will return UNCHANGED, |
--- |
3321 |
/// If this attribute is already fixed, this method will return UNCHANGED, |
--- |
| 3322 |
/// otherwise it delegates to `AbstractAttribute::updateImpl`. |
--- |
3322 |
/// otherwise it delegates to `AbstractAttribute::updateImpl`. |
--- |
| 3323 |
/// |
--- |
3323 |
/// |
--- |
| 3324 |
/// \Return CHANGED if the internal state changed, otherwise UNCHANGED. |
--- |
3324 |
/// \Return CHANGED if the internal state changed, otherwise UNCHANGED. |
--- |
| 3325 |
ChangeStatus update(Attributor &A); |
--- |
3325 |
ChangeStatus update(Attributor &A); |
--- |
| 3326 |
|
--- |
3326 |
|
--- |
| 3327 |
/// Hook for the Attributor to trigger the manifestation of the information |
--- |
3327 |
/// Hook for the Attributor to trigger the manifestation of the information |
--- |
| 3328 |
/// represented by the abstract attribute in the LLVM-IR. |
--- |
3328 |
/// represented by the abstract attribute in the LLVM-IR. |
--- |
| 3329 |
/// |
--- |
3329 |
/// |
--- |
| 3330 |
/// \Return CHANGED if the IR was altered, otherwise UNCHANGED. |
--- |
3330 |
/// \Return CHANGED if the IR was altered, otherwise UNCHANGED. |
--- |
| 3331 |
virtual ChangeStatus manifest(Attributor &A) { |
0 |
3331 |
virtual ChangeStatus manifest(Attributor &A) { |
0 |
| 3332 |
return ChangeStatus::UNCHANGED; |
0 |
3332 |
return ChangeStatus::UNCHANGED; |
0 |
| 3333 |
} |
--- |
3333 |
} |
--- |
| 3334 |
|
--- |
3334 |
|
--- |
| 3335 |
/// Hook to enable custom statistic tracking, called after manifest that |
--- |
3335 |
/// Hook to enable custom statistic tracking, called after manifest that |
--- |
| 3336 |
/// resulted in a change if statistics are enabled. |
--- |
3336 |
/// resulted in a change if statistics are enabled. |
--- |
| 3337 |
/// |
--- |
3337 |
/// |
--- |
| 3338 |
/// We require subclasses to provide an implementation so we remember to |
--- |
3338 |
/// We require subclasses to provide an implementation so we remember to |
--- |
| 3339 |
/// add statistics for them. |
--- |
3339 |
/// add statistics for them. |
--- |
| 3340 |
virtual void trackStatistics() const = 0; |
--- |
3340 |
virtual void trackStatistics() const = 0; |
--- |
| 3341 |
|
--- |
3341 |
|
--- |
| 3342 |
/// The actual update/transfer function which has to be implemented by the |
--- |
3342 |
/// The actual update/transfer function which has to be implemented by the |
--- |
| 3343 |
/// derived classes. |
--- |
3343 |
/// derived classes. |
--- |
| 3344 |
/// |
--- |
3344 |
/// |
--- |
| 3345 |
/// If it is called, the environment has changed and we have to determine if |
--- |
3345 |
/// If it is called, the environment has changed and we have to determine if |
--- |
| 3346 |
/// the current information is still valid or adjust it otherwise. |
--- |
3346 |
/// the current information is still valid or adjust it otherwise. |
--- |
| 3347 |
/// |
--- |
3347 |
/// |
--- |
| 3348 |
/// \Return CHANGED if the internal state changed, otherwise UNCHANGED. |
--- |
3348 |
/// \Return CHANGED if the internal state changed, otherwise UNCHANGED. |
--- |
| 3349 |
virtual ChangeStatus updateImpl(Attributor &A) = 0; |
--- |
3349 |
virtual ChangeStatus updateImpl(Attributor &A) = 0; |
--- |
| 3350 |
}; |
--- |
3350 |
}; |
--- |
| 3351 |
|
--- |
3351 |
|
--- |
| 3352 |
/// Forward declarations of output streams for debug purposes. |
--- |
3352 |
/// Forward declarations of output streams for debug purposes. |
--- |
| 3353 |
/// |
--- |
3353 |
/// |
--- |
| 3354 |
///{ |
--- |
3354 |
///{ |
--- |
| 3355 |
raw_ostream &operator<<(raw_ostream &OS, const AbstractAttribute &AA); |
--- |
3355 |
raw_ostream &operator<<(raw_ostream &OS, const AbstractAttribute &AA); |
--- |
| 3356 |
raw_ostream &operator<<(raw_ostream &OS, ChangeStatus S); |
--- |
3356 |
raw_ostream &operator<<(raw_ostream &OS, ChangeStatus S); |
--- |
| 3357 |
raw_ostream &operator<<(raw_ostream &OS, IRPosition::Kind); |
--- |
3357 |
raw_ostream &operator<<(raw_ostream &OS, IRPosition::Kind); |
--- |
| 3358 |
raw_ostream &operator<<(raw_ostream &OS, const IRPosition &); |
--- |
3358 |
raw_ostream &operator<<(raw_ostream &OS, const IRPosition &); |
--- |
| 3359 |
raw_ostream &operator<<(raw_ostream &OS, const AbstractState &State); |
--- |
3359 |
raw_ostream &operator<<(raw_ostream &OS, const AbstractState &State); |
--- |
| 3360 |
template |
--- |
3360 |
template |
--- |
| 3361 |
raw_ostream & |
--- |
3361 |
raw_ostream & |
--- |
| 3362 |
operator<<(raw_ostream &OS, |
--- |
3362 |
operator<<(raw_ostream &OS, |
--- |
| 3363 |
const IntegerStateBase &S) { |
--- |
3363 |
const IntegerStateBase &S) { |
--- |
| 3364 |
return OS << "(" << S.getKnown() << "-" << S.getAssumed() << ")" |
--- |
3364 |
return OS << "(" << S.getKnown() << "-" << S.getAssumed() << ")" |
--- |
| 3365 |
<< static_cast(S); |
--- |
3365 |
<< static_cast(S); |
--- |
| 3366 |
} |
--- |
3366 |
} |
--- |
| 3367 |
raw_ostream &operator<<(raw_ostream &OS, const IntegerRangeState &State); |
--- |
3367 |
raw_ostream &operator<<(raw_ostream &OS, const IntegerRangeState &State); |
--- |
| 3368 |
///} |
--- |
3368 |
///} |
--- |
| 3369 |
|
--- |
3369 |
|
--- |
| 3370 |
struct AttributorPass : public PassInfoMixin { |
--- |
3370 |
struct AttributorPass : public PassInfoMixin { |
--- |
| 3371 |
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
--- |
3371 |
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
--- |
| 3372 |
}; |
--- |
3372 |
}; |
--- |
| 3373 |
struct AttributorCGSCCPass : public PassInfoMixin { |
--- |
3373 |
struct AttributorCGSCCPass : public PassInfoMixin { |
--- |
| 3374 |
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, |
--- |
3374 |
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, |
--- |
| 3375 |
LazyCallGraph &CG, CGSCCUpdateResult &UR); |
--- |
3375 |
LazyCallGraph &CG, CGSCCUpdateResult &UR); |
--- |
| 3376 |
}; |
--- |
3376 |
}; |
--- |
| 3377 |
|
--- |
3377 |
|
--- |
| 3378 |
/// Helper function to clamp a state \p S of type \p StateType with the |
--- |
3378 |
/// Helper function to clamp a state \p S of type \p StateType with the |
--- |
| 3379 |
/// information in \p R and indicate/return if \p S did change (as-in update is |
--- |
3379 |
/// information in \p R and indicate/return if \p S did change (as-in update is |
--- |
| 3380 |
/// required to be run again). |
--- |
3380 |
/// required to be run again). |
--- |
| 3381 |
template |
--- |
3381 |
template |
--- |
| 3382 |
ChangeStatus clampStateAndIndicateChange(StateType &S, const StateType &R) { |
--- |
3382 |
ChangeStatus clampStateAndIndicateChange(StateType &S, const StateType &R) { |
--- |
| 3383 |
auto Assumed = S.getAssumed(); |
--- |
3383 |
auto Assumed = S.getAssumed(); |
--- |
| 3384 |
S ^= R; |
--- |
3384 |
S ^= R; |
--- |
| 3385 |
return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED |
--- |
3385 |
return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED |
--- |
| 3386 |
: ChangeStatus::CHANGED; |
--- |
3386 |
: ChangeStatus::CHANGED; |
--- |
| 3387 |
} |
--- |
3387 |
} |
--- |
| 3388 |
|
--- |
3388 |
|
--- |
| 3389 |
/// ---------------------------------------------------------------------------- |
--- |
3389 |
/// ---------------------------------------------------------------------------- |
--- |
| 3390 |
/// Abstract Attribute Classes |
--- |
3390 |
/// Abstract Attribute Classes |
--- |
| 3391 |
/// ---------------------------------------------------------------------------- |
--- |
3391 |
/// ---------------------------------------------------------------------------- |
--- |
| 3392 |
|
--- |
3392 |
|
--- |
| 3393 |
struct AANoUnwind |
--- |
3393 |
struct AANoUnwind |
--- |
| 3394 |
: public IRAttribute
| --- |
3394 |
: public IRAttribute
| --- |
| |
| 3395 |
StateWrapper, |
--- |
3395 |
StateWrapper, |
--- |
| 3396 |
AANoUnwind> { |
--- |
3396 |
AANoUnwind> { |
--- |
| 3397 |
AANoUnwind(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3397 |
AANoUnwind(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3398 |
|
--- |
3398 |
|
--- |
| 3399 |
/// Returns true if nounwind is assumed. |
--- |
3399 |
/// Returns true if nounwind is assumed. |
--- |
| 3400 |
bool isAssumedNoUnwind() const { return getAssumed(); } |
--- |
3400 |
bool isAssumedNoUnwind() const { return getAssumed(); } |
--- |
| 3401 |
|
--- |
3401 |
|
--- |
| 3402 |
/// Returns true if nounwind is known. |
--- |
3402 |
/// Returns true if nounwind is known. |
--- |
| 3403 |
bool isKnownNoUnwind() const { return getKnown(); } |
--- |
3403 |
bool isKnownNoUnwind() const { return getKnown(); } |
--- |
| 3404 |
|
--- |
3404 |
|
--- |
| 3405 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3405 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3406 |
static AANoUnwind &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3406 |
static AANoUnwind &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3407 |
|
--- |
3407 |
|
--- |
| 3408 |
/// See AbstractAttribute::getName() |
--- |
3408 |
/// See AbstractAttribute::getName() |
--- |
| 3409 |
const std::string getName() const override { return "AANoUnwind"; } |
--- |
3409 |
const std::string getName() const override { return "AANoUnwind"; } |
--- |
| 3410 |
|
--- |
3410 |
|
--- |
| 3411 |
/// See AbstractAttribute::getIdAddr() |
--- |
3411 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3412 |
const char *getIdAddr() const override { return &ID; } |
--- |
3412 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3413 |
|
--- |
3413 |
|
--- |
| 3414 |
/// This function should return true if the type of the \p AA is AANoUnwind |
--- |
3414 |
/// This function should return true if the type of the \p AA is AANoUnwind |
--- |
| 3415 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3415 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3416 |
return (AA->getIdAddr() == &ID); |
--- |
3416 |
return (AA->getIdAddr() == &ID); |
--- |
| 3417 |
} |
--- |
3417 |
} |
--- |
| 3418 |
|
--- |
3418 |
|
--- |
| 3419 |
/// Unique ID (due to the unique address) |
--- |
3419 |
/// Unique ID (due to the unique address) |
--- |
| 3420 |
static const char ID; |
--- |
3420 |
static const char ID; |
--- |
| 3421 |
}; |
--- |
3421 |
}; |
--- |
| 3422 |
|
--- |
3422 |
|
--- |
| 3423 |
struct AANoSync |
--- |
3423 |
struct AANoSync |
--- |
| 3424 |
: public IRAttribute
| --- |
3424 |
: public IRAttribute
| --- |
| |
| 3425 |
StateWrapper, |
--- |
3425 |
StateWrapper, |
--- |
| 3426 |
AANoSync> { |
--- |
3426 |
AANoSync> { |
--- |
| 3427 |
AANoSync(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3427 |
AANoSync(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3428 |
|
--- |
3428 |
|
--- |
| 3429 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
3429 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 3430 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3430 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3431 |
bool IgnoreSubsumingPositions = false) { |
--- |
3431 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 3432 |
// Note: This is also run for non-IPO amendable functions. |
--- |
3432 |
// Note: This is also run for non-IPO amendable functions. |
--- |
| 3433 |
assert(ImpliedAttributeKind == Attribute::NoSync); |
0 |
3433 |
assert(ImpliedAttributeKind == Attribute::NoSync); |
0 |
| 3434 |
if (A.hasAttr(IRP, {Attribute::NoSync}, IgnoreSubsumingPositions, |
0 |
3434 |
if (A.hasAttr(IRP, {Attribute::NoSync}, IgnoreSubsumingPositions, |
0 |
| 3435 |
Attribute::NoSync)) |
--- |
3435 |
Attribute::NoSync)) |
--- |
| 3436 |
return true; |
0 |
3436 |
return true; |
0 |
| 3437 |
|
--- |
3437 |
|
--- |
| 3438 |
// Check for readonly + non-convergent. |
--- |
3438 |
// Check for readonly + non-convergent. |
--- |
| 3439 |
// TODO: We should be able to use hasAttr for Attributes, not only |
--- |
3439 |
// TODO: We should be able to use hasAttr for Attributes, not only |
--- |
| 3440 |
// AttrKinds. |
--- |
3440 |
// AttrKinds. |
--- |
| 3441 |
Function *F = IRP.getAssociatedFunction(); |
0 |
3441 |
Function *F = IRP.getAssociatedFunction(); |
0 |
| 3442 |
if (!F || F->isConvergent()) |
0 |
3442 |
if (!F || F->isConvergent()) |
0 |
| 3443 |
return false; |
0 |
3443 |
return false; |
0 |
| 3444 |
|
--- |
3444 |
|
--- |
| 3445 |
SmallVector Attrs; |
0 |
3445 |
SmallVector Attrs; |
0 |
| 3446 |
A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions); |
0 |
3446 |
A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions); |
0 |
| 3447 |
|
--- |
3447 |
|
--- |
| 3448 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
3448 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
| 3449 |
for (const Attribute &Attr : Attrs) |
0 |
3449 |
for (const Attribute &Attr : Attrs) |
0 |
| 3450 |
ME &= Attr.getMemoryEffects(); |
0 |
3450 |
ME &= Attr.getMemoryEffects(); |
0 |
| 3451 |
|
--- |
3451 |
|
--- |
| 3452 |
if (!ME.onlyReadsMemory()) |
0 |
3452 |
if (!ME.onlyReadsMemory()) |
0 |
| 3453 |
return false; |
0 |
3453 |
return false; |
0 |
| 3454 |
|
--- |
3454 |
|
--- |
| 3455 |
A.manifestAttrs(IRP, Attribute::get(F->getContext(), Attribute::NoSync)); |
0 |
3455 |
A.manifestAttrs(IRP, Attribute::get(F->getContext(), Attribute::NoSync)); |
0 |
| 3456 |
return true; |
0 |
3456 |
return true; |
0 |
| 3457 |
} |
0 |
3457 |
} |
0 |
| 3458 |
|
--- |
3458 |
|
--- |
| 3459 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
3459 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 3460 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
3460 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 3461 |
if (!IRP.isFunctionScope() && |
0 |
3461 |
if (!IRP.isFunctionScope() && |
0 |
| 3462 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
3462 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 3463 |
return false; |
0 |
3463 |
return false; |
0 |
| 3464 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
3464 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 3465 |
} |
--- |
3465 |
} |
--- |
| 3466 |
|
--- |
3466 |
|
--- |
| 3467 |
/// Returns true if "nosync" is assumed. |
--- |
3467 |
/// Returns true if "nosync" is assumed. |
--- |
| 3468 |
bool isAssumedNoSync() const { return getAssumed(); } |
--- |
3468 |
bool isAssumedNoSync() const { return getAssumed(); } |
--- |
| 3469 |
|
--- |
3469 |
|
--- |
| 3470 |
/// Returns true if "nosync" is known. |
--- |
3470 |
/// Returns true if "nosync" is known. |
--- |
| 3471 |
bool isKnownNoSync() const { return getKnown(); } |
--- |
3471 |
bool isKnownNoSync() const { return getKnown(); } |
--- |
| 3472 |
|
--- |
3472 |
|
--- |
| 3473 |
/// Helper function used to determine whether an instruction is non-relaxed |
--- |
3473 |
/// Helper function used to determine whether an instruction is non-relaxed |
--- |
| 3474 |
/// atomic. In other words, if an atomic instruction does not have unordered |
--- |
3474 |
/// atomic. In other words, if an atomic instruction does not have unordered |
--- |
| 3475 |
/// or monotonic ordering |
--- |
3475 |
/// or monotonic ordering |
--- |
| 3476 |
static bool isNonRelaxedAtomic(const Instruction *I); |
--- |
3476 |
static bool isNonRelaxedAtomic(const Instruction *I); |
--- |
| 3477 |
|
--- |
3477 |
|
--- |
| 3478 |
/// Helper function specific for intrinsics which are potentially volatile. |
--- |
3478 |
/// Helper function specific for intrinsics which are potentially volatile. |
--- |
| 3479 |
static bool isNoSyncIntrinsic(const Instruction *I); |
--- |
3479 |
static bool isNoSyncIntrinsic(const Instruction *I); |
--- |
| 3480 |
|
--- |
3480 |
|
--- |
| 3481 |
/// Helper function to determine if \p CB is an aligned (GPU) barrier. Aligned |
--- |
3481 |
/// Helper function to determine if \p CB is an aligned (GPU) barrier. Aligned |
--- |
| 3482 |
/// barriers have to be executed by all threads. The flag \p ExecutedAligned |
--- |
3482 |
/// barriers have to be executed by all threads. The flag \p ExecutedAligned |
--- |
| 3483 |
/// indicates if the call is executed by all threads in a (thread) block in an |
--- |
3483 |
/// indicates if the call is executed by all threads in a (thread) block in an |
--- |
| 3484 |
/// aligned way. If that is the case, non-aligned barriers are effectively |
--- |
3484 |
/// aligned way. If that is the case, non-aligned barriers are effectively |
--- |
| 3485 |
/// aligned barriers. |
--- |
3485 |
/// aligned barriers. |
--- |
| 3486 |
static bool isAlignedBarrier(const CallBase &CB, bool ExecutedAligned); |
--- |
3486 |
static bool isAlignedBarrier(const CallBase &CB, bool ExecutedAligned); |
--- |
| 3487 |
|
--- |
3487 |
|
--- |
| 3488 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3488 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3489 |
static AANoSync &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3489 |
static AANoSync &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3490 |
|
--- |
3490 |
|
--- |
| 3491 |
/// See AbstractAttribute::getName() |
--- |
3491 |
/// See AbstractAttribute::getName() |
--- |
| 3492 |
const std::string getName() const override { return "AANoSync"; } |
--- |
3492 |
const std::string getName() const override { return "AANoSync"; } |
--- |
| 3493 |
|
--- |
3493 |
|
--- |
| 3494 |
/// See AbstractAttribute::getIdAddr() |
--- |
3494 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3495 |
const char *getIdAddr() const override { return &ID; } |
--- |
3495 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3496 |
|
--- |
3496 |
|
--- |
| 3497 |
/// This function should return true if the type of the \p AA is AANoSync |
--- |
3497 |
/// This function should return true if the type of the \p AA is AANoSync |
--- |
| 3498 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3498 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3499 |
return (AA->getIdAddr() == &ID); |
--- |
3499 |
return (AA->getIdAddr() == &ID); |
--- |
| 3500 |
} |
--- |
3500 |
} |
--- |
| 3501 |
|
--- |
3501 |
|
--- |
| 3502 |
/// Unique ID (due to the unique address) |
--- |
3502 |
/// Unique ID (due to the unique address) |
--- |
| 3503 |
static const char ID; |
--- |
3503 |
static const char ID; |
--- |
| 3504 |
}; |
--- |
3504 |
}; |
--- |
| 3505 |
|
--- |
3505 |
|
--- |
| 3506 |
/// An abstract interface for all nonnull attributes. |
--- |
3506 |
/// An abstract interface for all nonnull attributes. |
--- |
| 3507 |
struct AAMustProgress |
--- |
3507 |
struct AAMustProgress |
--- |
| 3508 |
: public IRAttribute
| --- |
3508 |
: public IRAttribute
| --- |
| |
| 3509 |
StateWrapper, |
--- |
3509 |
StateWrapper, |
--- |
| 3510 |
AAMustProgress> { |
--- |
3510 |
AAMustProgress> { |
--- |
| 3511 |
AAMustProgress(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3511 |
AAMustProgress(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3512 |
|
--- |
3512 |
|
--- |
| 3513 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
3513 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 3514 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3514 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3515 |
bool IgnoreSubsumingPositions = false) { |
--- |
3515 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 3516 |
// Note: This is also run for non-IPO amendable functions. |
--- |
3516 |
// Note: This is also run for non-IPO amendable functions. |
--- |
| 3517 |
assert(ImpliedAttributeKind == Attribute::MustProgress); |
0 |
3517 |
assert(ImpliedAttributeKind == Attribute::MustProgress); |
0 |
| 3518 |
return A.hasAttr(IRP, {Attribute::MustProgress, Attribute::WillReturn}, |
0 |
3518 |
return A.hasAttr(IRP, {Attribute::MustProgress, Attribute::WillReturn}, |
0 |
| 3519 |
IgnoreSubsumingPositions, Attribute::MustProgress); |
0 |
3519 |
IgnoreSubsumingPositions, Attribute::MustProgress); |
0 |
| 3520 |
} |
--- |
3520 |
} |
--- |
| 3521 |
|
--- |
3521 |
|
--- |
| 3522 |
/// Return true if we assume that the underlying value is nonnull. |
--- |
3522 |
/// Return true if we assume that the underlying value is nonnull. |
--- |
| 3523 |
bool isAssumedMustProgress() const { return getAssumed(); } |
--- |
3523 |
bool isAssumedMustProgress() const { return getAssumed(); } |
--- |
| 3524 |
|
--- |
3524 |
|
--- |
| 3525 |
/// Return true if we know that underlying value is nonnull. |
--- |
3525 |
/// Return true if we know that underlying value is nonnull. |
--- |
| 3526 |
bool isKnownMustProgress() const { return getKnown(); } |
--- |
3526 |
bool isKnownMustProgress() const { return getKnown(); } |
--- |
| 3527 |
|
--- |
3527 |
|
--- |
| 3528 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3528 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3529 |
static AAMustProgress &createForPosition(const IRPosition &IRP, |
--- |
3529 |
static AAMustProgress &createForPosition(const IRPosition &IRP, |
--- |
| 3530 |
Attributor &A); |
--- |
3530 |
Attributor &A); |
--- |
| 3531 |
|
--- |
3531 |
|
--- |
| 3532 |
/// See AbstractAttribute::getName() |
--- |
3532 |
/// See AbstractAttribute::getName() |
--- |
| 3533 |
const std::string getName() const override { return "AAMustProgress"; } |
--- |
3533 |
const std::string getName() const override { return "AAMustProgress"; } |
--- |
| 3534 |
|
--- |
3534 |
|
--- |
| 3535 |
/// See AbstractAttribute::getIdAddr() |
--- |
3535 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3536 |
const char *getIdAddr() const override { return &ID; } |
--- |
3536 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3537 |
|
--- |
3537 |
|
--- |
| 3538 |
/// This function should return true if the type of the \p AA is |
--- |
3538 |
/// This function should return true if the type of the \p AA is |
--- |
| 3539 |
/// AAMustProgress |
--- |
3539 |
/// AAMustProgress |
--- |
| 3540 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3540 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3541 |
return (AA->getIdAddr() == &ID); |
--- |
3541 |
return (AA->getIdAddr() == &ID); |
--- |
| 3542 |
} |
--- |
3542 |
} |
--- |
| 3543 |
|
--- |
3543 |
|
--- |
| 3544 |
/// Unique ID (due to the unique address) |
--- |
3544 |
/// Unique ID (due to the unique address) |
--- |
| 3545 |
static const char ID; |
--- |
3545 |
static const char ID; |
--- |
| 3546 |
}; |
--- |
3546 |
}; |
--- |
| 3547 |
|
--- |
3547 |
|
--- |
| 3548 |
/// An abstract interface for all nonnull attributes. |
--- |
3548 |
/// An abstract interface for all nonnull attributes. |
--- |
| 3549 |
struct AANonNull |
--- |
3549 |
struct AANonNull |
--- |
| 3550 |
: public IRAttribute
| --- |
3550 |
: public IRAttribute
| --- |
| |
| 3551 |
StateWrapper, |
--- |
3551 |
StateWrapper, |
--- |
| 3552 |
AANonNull> { |
--- |
3552 |
AANonNull> { |
--- |
| 3553 |
AANonNull(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3553 |
AANonNull(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3554 |
|
--- |
3554 |
|
--- |
| 3555 |
/// See AbstractAttribute::hasTrivialInitializer. |
--- |
3555 |
/// See AbstractAttribute::hasTrivialInitializer. |
--- |
| 3556 |
static bool hasTrivialInitializer() { return false; } |
0 |
3556 |
static bool hasTrivialInitializer() { return false; } |
0 |
| 3557 |
|
--- |
3557 |
|
--- |
| 3558 |
/// See IRAttribute::isImpliedByUndef. |
--- |
3558 |
/// See IRAttribute::isImpliedByUndef. |
--- |
| 3559 |
/// Undef is not necessarily nonnull as nonnull + noundef would cause poison. |
--- |
3559 |
/// Undef is not necessarily nonnull as nonnull + noundef would cause poison. |
--- |
| 3560 |
/// Poison implies nonnull though. |
--- |
3560 |
/// Poison implies nonnull though. |
--- |
| 3561 |
static bool isImpliedByUndef() { return false; } |
--- |
3561 |
static bool isImpliedByUndef() { return false; } |
--- |
| 3562 |
|
--- |
3562 |
|
--- |
| 3563 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
3563 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 3564 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
3564 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 3565 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
3565 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 3566 |
return false; |
0 |
3566 |
return false; |
0 |
| 3567 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
3567 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 3568 |
} |
--- |
3568 |
} |
--- |
| 3569 |
|
--- |
3569 |
|
--- |
| 3570 |
/// See AbstractAttribute::isImpliedByIR(...). |
--- |
3570 |
/// See AbstractAttribute::isImpliedByIR(...). |
--- |
| 3571 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
3571 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
| 3572 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3572 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3573 |
bool IgnoreSubsumingPositions = false); |
--- |
3573 |
bool IgnoreSubsumingPositions = false); |
--- |
| 3574 |
|
--- |
3574 |
|
--- |
| 3575 |
/// Return true if we assume that the underlying value is nonnull. |
--- |
3575 |
/// Return true if we assume that the underlying value is nonnull. |
--- |
| 3576 |
bool isAssumedNonNull() const { return getAssumed(); } |
--- |
3576 |
bool isAssumedNonNull() const { return getAssumed(); } |
--- |
| 3577 |
|
--- |
3577 |
|
--- |
| 3578 |
/// Return true if we know that underlying value is nonnull. |
--- |
3578 |
/// Return true if we know that underlying value is nonnull. |
--- |
| 3579 |
bool isKnownNonNull() const { return getKnown(); } |
--- |
3579 |
bool isKnownNonNull() const { return getKnown(); } |
--- |
| 3580 |
|
--- |
3580 |
|
--- |
| 3581 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3581 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3582 |
static AANonNull &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3582 |
static AANonNull &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3583 |
|
--- |
3583 |
|
--- |
| 3584 |
/// See AbstractAttribute::getName() |
--- |
3584 |
/// See AbstractAttribute::getName() |
--- |
| 3585 |
const std::string getName() const override { return "AANonNull"; } |
--- |
3585 |
const std::string getName() const override { return "AANonNull"; } |
--- |
| 3586 |
|
--- |
3586 |
|
--- |
| 3587 |
/// See AbstractAttribute::getIdAddr() |
--- |
3587 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3588 |
const char *getIdAddr() const override { return &ID; } |
--- |
3588 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3589 |
|
--- |
3589 |
|
--- |
| 3590 |
/// This function should return true if the type of the \p AA is AANonNull |
--- |
3590 |
/// This function should return true if the type of the \p AA is AANonNull |
--- |
| 3591 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3591 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3592 |
return (AA->getIdAddr() == &ID); |
--- |
3592 |
return (AA->getIdAddr() == &ID); |
--- |
| 3593 |
} |
--- |
3593 |
} |
--- |
| 3594 |
|
--- |
3594 |
|
--- |
| 3595 |
/// Unique ID (due to the unique address) |
--- |
3595 |
/// Unique ID (due to the unique address) |
--- |
| 3596 |
static const char ID; |
--- |
3596 |
static const char ID; |
--- |
| 3597 |
}; |
--- |
3597 |
}; |
--- |
| 3598 |
|
--- |
3598 |
|
--- |
| 3599 |
/// An abstract attribute for norecurse. |
--- |
3599 |
/// An abstract attribute for norecurse. |
--- |
| 3600 |
struct AANoRecurse |
--- |
3600 |
struct AANoRecurse |
--- |
| 3601 |
: public IRAttribute
| --- |
3601 |
: public IRAttribute
| --- |
| |
| 3602 |
StateWrapper, |
--- |
3602 |
StateWrapper, |
--- |
| 3603 |
AANoRecurse> { |
--- |
3603 |
AANoRecurse> { |
--- |
| 3604 |
AANoRecurse(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3604 |
AANoRecurse(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3605 |
|
--- |
3605 |
|
--- |
| 3606 |
/// Return true if "norecurse" is assumed. |
--- |
3606 |
/// Return true if "norecurse" is assumed. |
--- |
| 3607 |
bool isAssumedNoRecurse() const { return getAssumed(); } |
--- |
3607 |
bool isAssumedNoRecurse() const { return getAssumed(); } |
--- |
| 3608 |
|
--- |
3608 |
|
--- |
| 3609 |
/// Return true if "norecurse" is known. |
--- |
3609 |
/// Return true if "norecurse" is known. |
--- |
| 3610 |
bool isKnownNoRecurse() const { return getKnown(); } |
--- |
3610 |
bool isKnownNoRecurse() const { return getKnown(); } |
--- |
| 3611 |
|
--- |
3611 |
|
--- |
| 3612 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3612 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3613 |
static AANoRecurse &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3613 |
static AANoRecurse &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3614 |
|
--- |
3614 |
|
--- |
| 3615 |
/// See AbstractAttribute::getName() |
--- |
3615 |
/// See AbstractAttribute::getName() |
--- |
| 3616 |
const std::string getName() const override { return "AANoRecurse"; } |
--- |
3616 |
const std::string getName() const override { return "AANoRecurse"; } |
--- |
| 3617 |
|
--- |
3617 |
|
--- |
| 3618 |
/// See AbstractAttribute::getIdAddr() |
--- |
3618 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3619 |
const char *getIdAddr() const override { return &ID; } |
--- |
3619 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3620 |
|
--- |
3620 |
|
--- |
| 3621 |
/// This function should return true if the type of the \p AA is AANoRecurse |
--- |
3621 |
/// This function should return true if the type of the \p AA is AANoRecurse |
--- |
| 3622 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3622 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3623 |
return (AA->getIdAddr() == &ID); |
--- |
3623 |
return (AA->getIdAddr() == &ID); |
--- |
| 3624 |
} |
--- |
3624 |
} |
--- |
| 3625 |
|
--- |
3625 |
|
--- |
| 3626 |
/// Unique ID (due to the unique address) |
--- |
3626 |
/// Unique ID (due to the unique address) |
--- |
| 3627 |
static const char ID; |
--- |
3627 |
static const char ID; |
--- |
| 3628 |
}; |
--- |
3628 |
}; |
--- |
| 3629 |
|
--- |
3629 |
|
--- |
| 3630 |
/// An abstract attribute for willreturn. |
--- |
3630 |
/// An abstract attribute for willreturn. |
--- |
| 3631 |
struct AAWillReturn |
--- |
3631 |
struct AAWillReturn |
--- |
| 3632 |
: public IRAttribute
| --- |
3632 |
: public IRAttribute
| --- |
| |
| 3633 |
StateWrapper, |
--- |
3633 |
StateWrapper, |
--- |
| 3634 |
AAWillReturn> { |
--- |
3634 |
AAWillReturn> { |
--- |
| 3635 |
AAWillReturn(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3635 |
AAWillReturn(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3636 |
|
--- |
3636 |
|
--- |
| 3637 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
3637 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 3638 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3638 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3639 |
bool IgnoreSubsumingPositions = false) { |
--- |
3639 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 3640 |
// Note: This is also run for non-IPO amendable functions. |
--- |
3640 |
// Note: This is also run for non-IPO amendable functions. |
--- |
| 3641 |
assert(ImpliedAttributeKind == Attribute::WillReturn); |
0 |
3641 |
assert(ImpliedAttributeKind == Attribute::WillReturn); |
0 |
| 3642 |
if (IRAttribute::isImpliedByIR(A, IRP, ImpliedAttributeKind, |
0 |
3642 |
if (IRAttribute::isImpliedByIR(A, IRP, ImpliedAttributeKind, |
0 |
| 3643 |
IgnoreSubsumingPositions)) |
--- |
3643 |
IgnoreSubsumingPositions)) |
--- |
| 3644 |
return true; |
0 |
3644 |
return true; |
0 |
| 3645 |
if (!isImpliedByMustprogressAndReadonly(A, IRP)) |
0 |
3645 |
if (!isImpliedByMustprogressAndReadonly(A, IRP)) |
0 |
| 3646 |
return false; |
0 |
3646 |
return false; |
0 |
| 3647 |
A.manifestAttrs(IRP, Attribute::get(IRP.getAnchorValue().getContext(), |
0 |
3647 |
A.manifestAttrs(IRP, Attribute::get(IRP.getAnchorValue().getContext(), |
0 |
| 3648 |
Attribute::WillReturn)); |
--- |
3648 |
Attribute::WillReturn)); |
--- |
| 3649 |
return true; |
0 |
3649 |
return true; |
0 |
| 3650 |
} |
--- |
3650 |
} |
--- |
| 3651 |
|
--- |
3651 |
|
--- |
| 3652 |
/// Check for `mustprogress` and `readonly` as they imply `willreturn`. |
--- |
3652 |
/// Check for `mustprogress` and `readonly` as they imply `willreturn`. |
--- |
| 3653 |
static bool isImpliedByMustprogressAndReadonly(Attributor &A, |
0 |
3653 |
static bool isImpliedByMustprogressAndReadonly(Attributor &A, |
0 |
| 3654 |
const IRPosition &IRP) { |
--- |
3654 |
const IRPosition &IRP) { |
--- |
| 3655 |
// Check for `mustprogress` in the scope and the associated function which |
--- |
3655 |
// Check for `mustprogress` in the scope and the associated function which |
--- |
| 3656 |
// might be different if this is a call site. |
--- |
3656 |
// might be different if this is a call site. |
--- |
| 3657 |
if (!A.hasAttr(IRP, {Attribute::MustProgress})) |
0 |
3657 |
if (!A.hasAttr(IRP, {Attribute::MustProgress})) |
0 |
| 3658 |
return false; |
0 |
3658 |
return false; |
0 |
| 3659 |
|
--- |
3659 |
|
--- |
| 3660 |
SmallVector Attrs; |
0 |
3660 |
SmallVector Attrs; |
0 |
| 3661 |
A.getAttrs(IRP, {Attribute::Memory}, Attrs, |
0 |
3661 |
A.getAttrs(IRP, {Attribute::Memory}, Attrs, |
0 |
| 3662 |
/* IgnoreSubsumingPositions */ false); |
--- |
3662 |
/* IgnoreSubsumingPositions */ false); |
--- |
| 3663 |
|
--- |
3663 |
|
--- |
| 3664 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
3664 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
| 3665 |
for (const Attribute &Attr : Attrs) |
0 |
3665 |
for (const Attribute &Attr : Attrs) |
0 |
| 3666 |
ME &= Attr.getMemoryEffects(); |
0 |
3666 |
ME &= Attr.getMemoryEffects(); |
0 |
| 3667 |
return ME.onlyReadsMemory(); |
0 |
3667 |
return ME.onlyReadsMemory(); |
0 |
| 3668 |
} |
0 |
3668 |
} |
0 |
| 3669 |
|
--- |
3669 |
|
--- |
| 3670 |
/// Return true if "willreturn" is assumed. |
--- |
3670 |
/// Return true if "willreturn" is assumed. |
--- |
| 3671 |
bool isAssumedWillReturn() const { return getAssumed(); } |
--- |
3671 |
bool isAssumedWillReturn() const { return getAssumed(); } |
--- |
| 3672 |
|
--- |
3672 |
|
--- |
| 3673 |
/// Return true if "willreturn" is known. |
--- |
3673 |
/// Return true if "willreturn" is known. |
--- |
| 3674 |
bool isKnownWillReturn() const { return getKnown(); } |
--- |
3674 |
bool isKnownWillReturn() const { return getKnown(); } |
--- |
| 3675 |
|
--- |
3675 |
|
--- |
| 3676 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3676 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3677 |
static AAWillReturn &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3677 |
static AAWillReturn &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3678 |
|
--- |
3678 |
|
--- |
| 3679 |
/// See AbstractAttribute::getName() |
--- |
3679 |
/// See AbstractAttribute::getName() |
--- |
| 3680 |
const std::string getName() const override { return "AAWillReturn"; } |
--- |
3680 |
const std::string getName() const override { return "AAWillReturn"; } |
--- |
| 3681 |
|
--- |
3681 |
|
--- |
| 3682 |
/// See AbstractAttribute::getIdAddr() |
--- |
3682 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3683 |
const char *getIdAddr() const override { return &ID; } |
--- |
3683 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3684 |
|
--- |
3684 |
|
--- |
| 3685 |
/// This function should return true if the type of the \p AA is AAWillReturn |
--- |
3685 |
/// This function should return true if the type of the \p AA is AAWillReturn |
--- |
| 3686 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3686 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3687 |
return (AA->getIdAddr() == &ID); |
--- |
3687 |
return (AA->getIdAddr() == &ID); |
--- |
| 3688 |
} |
--- |
3688 |
} |
--- |
| 3689 |
|
--- |
3689 |
|
--- |
| 3690 |
/// Unique ID (due to the unique address) |
--- |
3690 |
/// Unique ID (due to the unique address) |
--- |
| 3691 |
static const char ID; |
--- |
3691 |
static const char ID; |
--- |
| 3692 |
}; |
--- |
3692 |
}; |
--- |
| 3693 |
|
--- |
3693 |
|
--- |
| 3694 |
/// An abstract attribute for undefined behavior. |
--- |
3694 |
/// An abstract attribute for undefined behavior. |
--- |
| 3695 |
struct AAUndefinedBehavior |
--- |
3695 |
struct AAUndefinedBehavior |
--- |
| 3696 |
: public StateWrapper { |
--- |
3696 |
: public StateWrapper { |
--- |
| 3697 |
using Base = StateWrapper; |
--- |
3697 |
using Base = StateWrapper; |
--- |
| 3698 |
AAUndefinedBehavior(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
3698 |
AAUndefinedBehavior(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 3699 |
|
--- |
3699 |
|
--- |
| 3700 |
/// Return true if "undefined behavior" is assumed. |
--- |
3700 |
/// Return true if "undefined behavior" is assumed. |
--- |
| 3701 |
bool isAssumedToCauseUB() const { return getAssumed(); } |
--- |
3701 |
bool isAssumedToCauseUB() const { return getAssumed(); } |
--- |
| 3702 |
|
--- |
3702 |
|
--- |
| 3703 |
/// Return true if "undefined behavior" is assumed for a specific instruction. |
--- |
3703 |
/// Return true if "undefined behavior" is assumed for a specific instruction. |
--- |
| 3704 |
virtual bool isAssumedToCauseUB(Instruction *I) const = 0; |
--- |
3704 |
virtual bool isAssumedToCauseUB(Instruction *I) const = 0; |
--- |
| 3705 |
|
--- |
3705 |
|
--- |
| 3706 |
/// Return true if "undefined behavior" is known. |
--- |
3706 |
/// Return true if "undefined behavior" is known. |
--- |
| 3707 |
bool isKnownToCauseUB() const { return getKnown(); } |
--- |
3707 |
bool isKnownToCauseUB() const { return getKnown(); } |
--- |
| 3708 |
|
--- |
3708 |
|
--- |
| 3709 |
/// Return true if "undefined behavior" is known for a specific instruction. |
--- |
3709 |
/// Return true if "undefined behavior" is known for a specific instruction. |
--- |
| 3710 |
virtual bool isKnownToCauseUB(Instruction *I) const = 0; |
--- |
3710 |
virtual bool isKnownToCauseUB(Instruction *I) const = 0; |
--- |
| 3711 |
|
--- |
3711 |
|
--- |
| 3712 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3712 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3713 |
static AAUndefinedBehavior &createForPosition(const IRPosition &IRP, |
--- |
3713 |
static AAUndefinedBehavior &createForPosition(const IRPosition &IRP, |
--- |
| 3714 |
Attributor &A); |
--- |
3714 |
Attributor &A); |
--- |
| 3715 |
|
--- |
3715 |
|
--- |
| 3716 |
/// See AbstractAttribute::getName() |
--- |
3716 |
/// See AbstractAttribute::getName() |
--- |
| 3717 |
const std::string getName() const override { return "AAUndefinedBehavior"; } |
--- |
3717 |
const std::string getName() const override { return "AAUndefinedBehavior"; } |
--- |
| 3718 |
|
--- |
3718 |
|
--- |
| 3719 |
/// See AbstractAttribute::getIdAddr() |
--- |
3719 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3720 |
const char *getIdAddr() const override { return &ID; } |
--- |
3720 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3721 |
|
--- |
3721 |
|
--- |
| 3722 |
/// This function should return true if the type of the \p AA is |
--- |
3722 |
/// This function should return true if the type of the \p AA is |
--- |
| 3723 |
/// AAUndefineBehavior |
--- |
3723 |
/// AAUndefineBehavior |
--- |
| 3724 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3724 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3725 |
return (AA->getIdAddr() == &ID); |
--- |
3725 |
return (AA->getIdAddr() == &ID); |
--- |
| 3726 |
} |
--- |
3726 |
} |
--- |
| 3727 |
|
--- |
3727 |
|
--- |
| 3728 |
/// Unique ID (due to the unique address) |
--- |
3728 |
/// Unique ID (due to the unique address) |
--- |
| 3729 |
static const char ID; |
--- |
3729 |
static const char ID; |
--- |
| 3730 |
}; |
--- |
3730 |
}; |
--- |
| 3731 |
|
--- |
3731 |
|
--- |
| 3732 |
/// An abstract interface to determine reachability of point A to B. |
--- |
3732 |
/// An abstract interface to determine reachability of point A to B. |
--- |
| 3733 |
struct AAIntraFnReachability |
--- |
3733 |
struct AAIntraFnReachability |
--- |
| 3734 |
: public StateWrapper { |
--- |
3734 |
: public StateWrapper { |
--- |
| 3735 |
using Base = StateWrapper; |
--- |
3735 |
using Base = StateWrapper; |
--- |
| 3736 |
AAIntraFnReachability(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
3736 |
AAIntraFnReachability(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 3737 |
|
--- |
3737 |
|
--- |
| 3738 |
/// Returns true if 'From' instruction is assumed to reach, 'To' instruction. |
--- |
3738 |
/// Returns true if 'From' instruction is assumed to reach, 'To' instruction. |
--- |
| 3739 |
/// Users should provide two positions they are interested in, and the class |
--- |
3739 |
/// Users should provide two positions they are interested in, and the class |
--- |
| 3740 |
/// determines (and caches) reachability. |
--- |
3740 |
/// determines (and caches) reachability. |
--- |
| 3741 |
virtual bool isAssumedReachable( |
--- |
3741 |
virtual bool isAssumedReachable( |
--- |
| 3742 |
Attributor &A, const Instruction &From, const Instruction &To, |
--- |
3742 |
Attributor &A, const Instruction &From, const Instruction &To, |
--- |
| 3743 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr) const = 0; |
--- |
3743 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr) const = 0; |
--- |
| 3744 |
|
--- |
3744 |
|
--- |
| 3745 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3745 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3746 |
static AAIntraFnReachability &createForPosition(const IRPosition &IRP, |
--- |
3746 |
static AAIntraFnReachability &createForPosition(const IRPosition &IRP, |
--- |
| 3747 |
Attributor &A); |
--- |
3747 |
Attributor &A); |
--- |
| 3748 |
|
--- |
3748 |
|
--- |
| 3749 |
/// See AbstractAttribute::getName() |
--- |
3749 |
/// See AbstractAttribute::getName() |
--- |
| 3750 |
const std::string getName() const override { return "AAIntraFnReachability"; } |
--- |
3750 |
const std::string getName() const override { return "AAIntraFnReachability"; } |
--- |
| 3751 |
|
--- |
3751 |
|
--- |
| 3752 |
/// See AbstractAttribute::getIdAddr() |
--- |
3752 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3753 |
const char *getIdAddr() const override { return &ID; } |
--- |
3753 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3754 |
|
--- |
3754 |
|
--- |
| 3755 |
/// This function should return true if the type of the \p AA is |
--- |
3755 |
/// This function should return true if the type of the \p AA is |
--- |
| 3756 |
/// AAIntraFnReachability |
--- |
3756 |
/// AAIntraFnReachability |
--- |
| 3757 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3757 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3758 |
return (AA->getIdAddr() == &ID); |
--- |
3758 |
return (AA->getIdAddr() == &ID); |
--- |
| 3759 |
} |
--- |
3759 |
} |
--- |
| 3760 |
|
--- |
3760 |
|
--- |
| 3761 |
/// Unique ID (due to the unique address) |
--- |
3761 |
/// Unique ID (due to the unique address) |
--- |
| 3762 |
static const char ID; |
--- |
3762 |
static const char ID; |
--- |
| 3763 |
}; |
--- |
3763 |
}; |
--- |
| 3764 |
|
--- |
3764 |
|
--- |
| 3765 |
/// An abstract interface for all noalias attributes. |
--- |
3765 |
/// An abstract interface for all noalias attributes. |
--- |
| 3766 |
struct AANoAlias |
--- |
3766 |
struct AANoAlias |
--- |
| 3767 |
: public IRAttribute
| --- |
3767 |
: public IRAttribute
| --- |
| |
| 3768 |
StateWrapper, |
--- |
3768 |
StateWrapper, |
--- |
| 3769 |
AANoAlias> { |
--- |
3769 |
AANoAlias> { |
--- |
| 3770 |
AANoAlias(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3770 |
AANoAlias(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3771 |
|
--- |
3771 |
|
--- |
| 3772 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
3772 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 3773 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
3773 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 3774 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
3774 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 3775 |
return false; |
0 |
3775 |
return false; |
0 |
| 3776 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
3776 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 3777 |
} |
--- |
3777 |
} |
--- |
| 3778 |
|
--- |
3778 |
|
--- |
| 3779 |
/// See IRAttribute::isImpliedByIR |
--- |
3779 |
/// See IRAttribute::isImpliedByIR |
--- |
| 3780 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
3780 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
| 3781 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3781 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3782 |
bool IgnoreSubsumingPositions = false); |
--- |
3782 |
bool IgnoreSubsumingPositions = false); |
--- |
| 3783 |
|
--- |
3783 |
|
--- |
| 3784 |
/// See AbstractAttribute::requiresCalleeForCallBase |
--- |
3784 |
/// See AbstractAttribute::requiresCalleeForCallBase |
--- |
| 3785 |
static bool requiresCalleeForCallBase() { return false; } |
0 |
3785 |
static bool requiresCalleeForCallBase() { return false; } |
0 |
| 3786 |
|
--- |
3786 |
|
--- |
| 3787 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
3787 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 3788 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
3788 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
| 3789 |
|
--- |
3789 |
|
--- |
| 3790 |
/// Return true if we assume that the underlying value is alias. |
--- |
3790 |
/// Return true if we assume that the underlying value is alias. |
--- |
| 3791 |
bool isAssumedNoAlias() const { return getAssumed(); } |
--- |
3791 |
bool isAssumedNoAlias() const { return getAssumed(); } |
--- |
| 3792 |
|
--- |
3792 |
|
--- |
| 3793 |
/// Return true if we know that underlying value is noalias. |
--- |
3793 |
/// Return true if we know that underlying value is noalias. |
--- |
| 3794 |
bool isKnownNoAlias() const { return getKnown(); } |
--- |
3794 |
bool isKnownNoAlias() const { return getKnown(); } |
--- |
| 3795 |
|
--- |
3795 |
|
--- |
| 3796 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3796 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3797 |
static AANoAlias &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3797 |
static AANoAlias &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3798 |
|
--- |
3798 |
|
--- |
| 3799 |
/// See AbstractAttribute::getName() |
--- |
3799 |
/// See AbstractAttribute::getName() |
--- |
| 3800 |
const std::string getName() const override { return "AANoAlias"; } |
--- |
3800 |
const std::string getName() const override { return "AANoAlias"; } |
--- |
| 3801 |
|
--- |
3801 |
|
--- |
| 3802 |
/// See AbstractAttribute::getIdAddr() |
--- |
3802 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3803 |
const char *getIdAddr() const override { return &ID; } |
--- |
3803 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3804 |
|
--- |
3804 |
|
--- |
| 3805 |
/// This function should return true if the type of the \p AA is AANoAlias |
--- |
3805 |
/// This function should return true if the type of the \p AA is AANoAlias |
--- |
| 3806 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3806 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3807 |
return (AA->getIdAddr() == &ID); |
--- |
3807 |
return (AA->getIdAddr() == &ID); |
--- |
| 3808 |
} |
--- |
3808 |
} |
--- |
| 3809 |
|
--- |
3809 |
|
--- |
| 3810 |
/// Unique ID (due to the unique address) |
--- |
3810 |
/// Unique ID (due to the unique address) |
--- |
| 3811 |
static const char ID; |
--- |
3811 |
static const char ID; |
--- |
| 3812 |
}; |
--- |
3812 |
}; |
--- |
| 3813 |
|
--- |
3813 |
|
--- |
| 3814 |
/// An AbstractAttribute for nofree. |
--- |
3814 |
/// An AbstractAttribute for nofree. |
--- |
| 3815 |
struct AANoFree |
--- |
3815 |
struct AANoFree |
--- |
| 3816 |
: public IRAttribute
| --- |
3816 |
: public IRAttribute
| --- |
| |
| 3817 |
StateWrapper, |
--- |
3817 |
StateWrapper, |
--- |
| 3818 |
AANoFree> { |
--- |
3818 |
AANoFree> { |
--- |
| 3819 |
AANoFree(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3819 |
AANoFree(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3820 |
|
--- |
3820 |
|
--- |
| 3821 |
/// See IRAttribute::isImpliedByIR |
--- |
3821 |
/// See IRAttribute::isImpliedByIR |
--- |
| 3822 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
3822 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 3823 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3823 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3824 |
bool IgnoreSubsumingPositions = false) { |
--- |
3824 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 3825 |
// Note: This is also run for non-IPO amendable functions. |
--- |
3825 |
// Note: This is also run for non-IPO amendable functions. |
--- |
| 3826 |
assert(ImpliedAttributeKind == Attribute::NoFree); |
0 |
3826 |
assert(ImpliedAttributeKind == Attribute::NoFree); |
0 |
| 3827 |
return A.hasAttr( |
0 |
3827 |
return A.hasAttr( |
0 |
| 3828 |
IRP, {Attribute::ReadNone, Attribute::ReadOnly, Attribute::NoFree}, |
--- |
3828 |
IRP, {Attribute::ReadNone, Attribute::ReadOnly, Attribute::NoFree}, |
--- |
| 3829 |
IgnoreSubsumingPositions, Attribute::NoFree); |
0 |
3829 |
IgnoreSubsumingPositions, Attribute::NoFree); |
0 |
| 3830 |
} |
--- |
3830 |
} |
--- |
| 3831 |
|
--- |
3831 |
|
--- |
| 3832 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
3832 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 3833 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
3833 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 3834 |
if (!IRP.isFunctionScope() && |
0 |
3834 |
if (!IRP.isFunctionScope() && |
0 |
| 3835 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
3835 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 3836 |
return false; |
0 |
3836 |
return false; |
0 |
| 3837 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
3837 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 3838 |
} |
--- |
3838 |
} |
--- |
| 3839 |
|
--- |
3839 |
|
--- |
| 3840 |
/// Return true if "nofree" is assumed. |
--- |
3840 |
/// Return true if "nofree" is assumed. |
--- |
| 3841 |
bool isAssumedNoFree() const { return getAssumed(); } |
--- |
3841 |
bool isAssumedNoFree() const { return getAssumed(); } |
--- |
| 3842 |
|
--- |
3842 |
|
--- |
| 3843 |
/// Return true if "nofree" is known. |
--- |
3843 |
/// Return true if "nofree" is known. |
--- |
| 3844 |
bool isKnownNoFree() const { return getKnown(); } |
--- |
3844 |
bool isKnownNoFree() const { return getKnown(); } |
--- |
| 3845 |
|
--- |
3845 |
|
--- |
| 3846 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3846 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3847 |
static AANoFree &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3847 |
static AANoFree &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3848 |
|
--- |
3848 |
|
--- |
| 3849 |
/// See AbstractAttribute::getName() |
--- |
3849 |
/// See AbstractAttribute::getName() |
--- |
| 3850 |
const std::string getName() const override { return "AANoFree"; } |
--- |
3850 |
const std::string getName() const override { return "AANoFree"; } |
--- |
| 3851 |
|
--- |
3851 |
|
--- |
| 3852 |
/// See AbstractAttribute::getIdAddr() |
--- |
3852 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3853 |
const char *getIdAddr() const override { return &ID; } |
--- |
3853 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3854 |
|
--- |
3854 |
|
--- |
| 3855 |
/// This function should return true if the type of the \p AA is AANoFree |
--- |
3855 |
/// This function should return true if the type of the \p AA is AANoFree |
--- |
| 3856 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3856 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3857 |
return (AA->getIdAddr() == &ID); |
--- |
3857 |
return (AA->getIdAddr() == &ID); |
--- |
| 3858 |
} |
--- |
3858 |
} |
--- |
| 3859 |
|
--- |
3859 |
|
--- |
| 3860 |
/// Unique ID (due to the unique address) |
--- |
3860 |
/// Unique ID (due to the unique address) |
--- |
| 3861 |
static const char ID; |
--- |
3861 |
static const char ID; |
--- |
| 3862 |
}; |
--- |
3862 |
}; |
--- |
| 3863 |
|
--- |
3863 |
|
--- |
| 3864 |
/// An AbstractAttribute for noreturn. |
--- |
3864 |
/// An AbstractAttribute for noreturn. |
--- |
| 3865 |
struct AANoReturn |
--- |
3865 |
struct AANoReturn |
--- |
| 3866 |
: public IRAttribute
| --- |
3866 |
: public IRAttribute
| --- |
| |
| 3867 |
StateWrapper, |
--- |
3867 |
StateWrapper, |
--- |
| 3868 |
AANoReturn> { |
--- |
3868 |
AANoReturn> { |
--- |
| 3869 |
AANoReturn(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
3869 |
AANoReturn(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 3870 |
|
--- |
3870 |
|
--- |
| 3871 |
/// Return true if the underlying object is assumed to never return. |
--- |
3871 |
/// Return true if the underlying object is assumed to never return. |
--- |
| 3872 |
bool isAssumedNoReturn() const { return getAssumed(); } |
--- |
3872 |
bool isAssumedNoReturn() const { return getAssumed(); } |
--- |
| 3873 |
|
--- |
3873 |
|
--- |
| 3874 |
/// Return true if the underlying object is known to never return. |
--- |
3874 |
/// Return true if the underlying object is known to never return. |
--- |
| 3875 |
bool isKnownNoReturn() const { return getKnown(); } |
--- |
3875 |
bool isKnownNoReturn() const { return getKnown(); } |
--- |
| 3876 |
|
--- |
3876 |
|
--- |
| 3877 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3877 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3878 |
static AANoReturn &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3878 |
static AANoReturn &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3879 |
|
--- |
3879 |
|
--- |
| 3880 |
/// See AbstractAttribute::getName() |
--- |
3880 |
/// See AbstractAttribute::getName() |
--- |
| 3881 |
const std::string getName() const override { return "AANoReturn"; } |
--- |
3881 |
const std::string getName() const override { return "AANoReturn"; } |
--- |
| 3882 |
|
--- |
3882 |
|
--- |
| 3883 |
/// See AbstractAttribute::getIdAddr() |
--- |
3883 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3884 |
const char *getIdAddr() const override { return &ID; } |
--- |
3884 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3885 |
|
--- |
3885 |
|
--- |
| 3886 |
/// This function should return true if the type of the \p AA is AANoReturn |
--- |
3886 |
/// This function should return true if the type of the \p AA is AANoReturn |
--- |
| 3887 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3887 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3888 |
return (AA->getIdAddr() == &ID); |
--- |
3888 |
return (AA->getIdAddr() == &ID); |
--- |
| 3889 |
} |
--- |
3889 |
} |
--- |
| 3890 |
|
--- |
3890 |
|
--- |
| 3891 |
/// Unique ID (due to the unique address) |
--- |
3891 |
/// Unique ID (due to the unique address) |
--- |
| 3892 |
static const char ID; |
--- |
3892 |
static const char ID; |
--- |
| 3893 |
}; |
--- |
3893 |
}; |
--- |
| 3894 |
|
--- |
3894 |
|
--- |
| 3895 |
/// An abstract interface for liveness abstract attribute. |
--- |
3895 |
/// An abstract interface for liveness abstract attribute. |
--- |
| 3896 |
struct AAIsDead |
--- |
3896 |
struct AAIsDead |
--- |
| 3897 |
: public StateWrapper, AbstractAttribute> { |
--- |
3897 |
: public StateWrapper, AbstractAttribute> { |
--- |
| 3898 |
using Base = StateWrapper, AbstractAttribute>; |
--- |
3898 |
using Base = StateWrapper, AbstractAttribute>; |
--- |
| 3899 |
AAIsDead(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
3899 |
AAIsDead(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 3900 |
|
--- |
3900 |
|
--- |
| 3901 |
/// State encoding bits. A set bit in the state means the property holds. |
--- |
3901 |
/// State encoding bits. A set bit in the state means the property holds. |
--- |
| 3902 |
enum { |
--- |
3902 |
enum { |
--- |
| 3903 |
HAS_NO_EFFECT = 1 << 0, |
--- |
3903 |
HAS_NO_EFFECT = 1 << 0, |
--- |
| 3904 |
IS_REMOVABLE = 1 << 1, |
--- |
3904 |
IS_REMOVABLE = 1 << 1, |
--- |
| 3905 |
|
--- |
3905 |
|
--- |
| 3906 |
IS_DEAD = HAS_NO_EFFECT | IS_REMOVABLE, |
--- |
3906 |
IS_DEAD = HAS_NO_EFFECT | IS_REMOVABLE, |
--- |
| 3907 |
}; |
--- |
3907 |
}; |
--- |
| 3908 |
static_assert(IS_DEAD == getBestState(), "Unexpected BEST_STATE value"); |
--- |
3908 |
static_assert(IS_DEAD == getBestState(), "Unexpected BEST_STATE value"); |
--- |
| 3909 |
|
--- |
3909 |
|
--- |
| 3910 |
protected: |
--- |
3910 |
protected: |
--- |
| 3911 |
/// The query functions are protected such that other attributes need to go |
--- |
3911 |
/// The query functions are protected such that other attributes need to go |
--- |
| 3912 |
/// through the Attributor interfaces: `Attributor::isAssumedDead(...)` |
--- |
3912 |
/// through the Attributor interfaces: `Attributor::isAssumedDead(...)` |
--- |
| 3913 |
|
--- |
3913 |
|
--- |
| 3914 |
/// Returns true if the underlying value is assumed dead. |
--- |
3914 |
/// Returns true if the underlying value is assumed dead. |
--- |
| 3915 |
virtual bool isAssumedDead() const = 0; |
--- |
3915 |
virtual bool isAssumedDead() const = 0; |
--- |
| 3916 |
|
--- |
3916 |
|
--- |
| 3917 |
/// Returns true if the underlying value is known dead. |
--- |
3917 |
/// Returns true if the underlying value is known dead. |
--- |
| 3918 |
virtual bool isKnownDead() const = 0; |
--- |
3918 |
virtual bool isKnownDead() const = 0; |
--- |
| 3919 |
|
--- |
3919 |
|
--- |
| 3920 |
/// Returns true if \p BB is known dead. |
--- |
3920 |
/// Returns true if \p BB is known dead. |
--- |
| 3921 |
virtual bool isKnownDead(const BasicBlock *BB) const = 0; |
--- |
3921 |
virtual bool isKnownDead(const BasicBlock *BB) const = 0; |
--- |
| 3922 |
|
--- |
3922 |
|
--- |
| 3923 |
/// Returns true if \p I is assumed dead. |
--- |
3923 |
/// Returns true if \p I is assumed dead. |
--- |
| 3924 |
virtual bool isAssumedDead(const Instruction *I) const = 0; |
--- |
3924 |
virtual bool isAssumedDead(const Instruction *I) const = 0; |
--- |
| 3925 |
|
--- |
3925 |
|
--- |
| 3926 |
/// Returns true if \p I is known dead. |
--- |
3926 |
/// Returns true if \p I is known dead. |
--- |
| 3927 |
virtual bool isKnownDead(const Instruction *I) const = 0; |
--- |
3927 |
virtual bool isKnownDead(const Instruction *I) const = 0; |
--- |
| 3928 |
|
--- |
3928 |
|
--- |
| 3929 |
/// Return true if the underlying value is a store that is known to be |
--- |
3929 |
/// Return true if the underlying value is a store that is known to be |
--- |
| 3930 |
/// removable. This is different from dead stores as the removable store |
--- |
3930 |
/// removable. This is different from dead stores as the removable store |
--- |
| 3931 |
/// can have an effect on live values, especially loads, but that effect |
--- |
3931 |
/// can have an effect on live values, especially loads, but that effect |
--- |
| 3932 |
/// is propagated which allows us to remove the store in turn. |
--- |
3932 |
/// is propagated which allows us to remove the store in turn. |
--- |
| 3933 |
virtual bool isRemovableStore() const { return false; } |
--- |
3933 |
virtual bool isRemovableStore() const { return false; } |
--- |
| 3934 |
|
--- |
3934 |
|
--- |
| 3935 |
/// This method is used to check if at least one instruction in a collection |
--- |
3935 |
/// This method is used to check if at least one instruction in a collection |
--- |
| 3936 |
/// of instructions is live. |
--- |
3936 |
/// of instructions is live. |
--- |
| 3937 |
template bool isLiveInstSet(T begin, T end) const { |
--- |
3937 |
template bool isLiveInstSet(T begin, T end) const { |
--- |
| 3938 |
for (const auto &I : llvm::make_range(begin, end)) { |
--- |
3938 |
for (const auto &I : llvm::make_range(begin, end)) { |
--- |
| 3939 |
assert(I->getFunction() == getIRPosition().getAssociatedFunction() && |
--- |
3939 |
assert(I->getFunction() == getIRPosition().getAssociatedFunction() && |
--- |
| 3940 |
"Instruction must be in the same anchor scope function."); |
--- |
3940 |
"Instruction must be in the same anchor scope function."); |
--- |
| 3941 |
|
--- |
3941 |
|
--- |
| 3942 |
if (!isAssumedDead(I)) |
--- |
3942 |
if (!isAssumedDead(I)) |
--- |
| 3943 |
return true; |
--- |
3943 |
return true; |
--- |
| 3944 |
} |
--- |
3944 |
} |
--- |
| 3945 |
|
--- |
3945 |
|
--- |
| 3946 |
return false; |
--- |
3946 |
return false; |
--- |
| 3947 |
} |
--- |
3947 |
} |
--- |
| 3948 |
|
--- |
3948 |
|
--- |
| 3949 |
public: |
--- |
3949 |
public: |
--- |
| 3950 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
3950 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 3951 |
static AAIsDead &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
3951 |
static AAIsDead &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 3952 |
|
--- |
3952 |
|
--- |
| 3953 |
/// Determine if \p F might catch asynchronous exceptions. |
--- |
3953 |
/// Determine if \p F might catch asynchronous exceptions. |
--- |
| 3954 |
static bool mayCatchAsynchronousExceptions(const Function &F) { |
0 |
3954 |
static bool mayCatchAsynchronousExceptions(const Function &F) { |
0 |
| 3955 |
return F.hasPersonalityFn() && !canSimplifyInvokeNoUnwind(&F); |
0 |
3955 |
return F.hasPersonalityFn() && !canSimplifyInvokeNoUnwind(&F); |
0 |
| 3956 |
} |
--- |
3956 |
} |
--- |
| 3957 |
|
--- |
3957 |
|
--- |
| 3958 |
/// Returns true if \p BB is assumed dead. |
--- |
3958 |
/// Returns true if \p BB is assumed dead. |
--- |
| 3959 |
virtual bool isAssumedDead(const BasicBlock *BB) const = 0; |
--- |
3959 |
virtual bool isAssumedDead(const BasicBlock *BB) const = 0; |
--- |
| 3960 |
|
--- |
3960 |
|
--- |
| 3961 |
/// Return if the edge from \p From BB to \p To BB is assumed dead. |
--- |
3961 |
/// Return if the edge from \p From BB to \p To BB is assumed dead. |
--- |
| 3962 |
/// This is specifically useful in AAReachability. |
--- |
3962 |
/// This is specifically useful in AAReachability. |
--- |
| 3963 |
virtual bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const { |
--- |
3963 |
virtual bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const { |
--- |
| 3964 |
return false; |
--- |
3964 |
return false; |
--- |
| 3965 |
} |
--- |
3965 |
} |
--- |
| 3966 |
|
--- |
3966 |
|
--- |
| 3967 |
/// See AbstractAttribute::getName() |
--- |
3967 |
/// See AbstractAttribute::getName() |
--- |
| 3968 |
const std::string getName() const override { return "AAIsDead"; } |
--- |
3968 |
const std::string getName() const override { return "AAIsDead"; } |
--- |
| 3969 |
|
--- |
3969 |
|
--- |
| 3970 |
/// See AbstractAttribute::getIdAddr() |
--- |
3970 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 3971 |
const char *getIdAddr() const override { return &ID; } |
--- |
3971 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 3972 |
|
--- |
3972 |
|
--- |
| 3973 |
/// This function should return true if the type of the \p AA is AAIsDead |
--- |
3973 |
/// This function should return true if the type of the \p AA is AAIsDead |
--- |
| 3974 |
static bool classof(const AbstractAttribute *AA) { |
--- |
3974 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 3975 |
return (AA->getIdAddr() == &ID); |
--- |
3975 |
return (AA->getIdAddr() == &ID); |
--- |
| 3976 |
} |
--- |
3976 |
} |
--- |
| 3977 |
|
--- |
3977 |
|
--- |
| 3978 |
/// Unique ID (due to the unique address) |
--- |
3978 |
/// Unique ID (due to the unique address) |
--- |
| 3979 |
static const char ID; |
--- |
3979 |
static const char ID; |
--- |
| 3980 |
|
--- |
3980 |
|
--- |
| 3981 |
friend struct Attributor; |
--- |
3981 |
friend struct Attributor; |
--- |
| 3982 |
}; |
--- |
3982 |
}; |
--- |
| 3983 |
|
--- |
3983 |
|
--- |
| 3984 |
/// State for dereferenceable attribute |
--- |
3984 |
/// State for dereferenceable attribute |
--- |
| 3985 |
struct DerefState : AbstractState { |
--- |
3985 |
struct DerefState : AbstractState { |
--- |
| 3986 |
|
--- |
3986 |
|
--- |
| 3987 |
static DerefState getBestState() { return DerefState(); } |
--- |
3987 |
static DerefState getBestState() { return DerefState(); } |
--- |
| 3988 |
static DerefState getBestState(const DerefState &) { return getBestState(); } |
--- |
3988 |
static DerefState getBestState(const DerefState &) { return getBestState(); } |
--- |
| 3989 |
|
--- |
3989 |
|
--- |
| 3990 |
/// Return the worst possible representable state. |
--- |
3990 |
/// Return the worst possible representable state. |
--- |
| 3991 |
static DerefState getWorstState() { |
--- |
3991 |
static DerefState getWorstState() { |
--- |
| 3992 |
DerefState DS; |
--- |
3992 |
DerefState DS; |
--- |
| 3993 |
DS.indicatePessimisticFixpoint(); |
--- |
3993 |
DS.indicatePessimisticFixpoint(); |
--- |
| 3994 |
return DS; |
--- |
3994 |
return DS; |
--- |
| 3995 |
} |
--- |
3995 |
} |
--- |
| 3996 |
static DerefState getWorstState(const DerefState &) { |
--- |
3996 |
static DerefState getWorstState(const DerefState &) { |
--- |
| 3997 |
return getWorstState(); |
--- |
3997 |
return getWorstState(); |
--- |
| 3998 |
} |
--- |
3998 |
} |
--- |
| 3999 |
|
--- |
3999 |
|
--- |
| 4000 |
/// State representing for dereferenceable bytes. |
--- |
4000 |
/// State representing for dereferenceable bytes. |
--- |
| 4001 |
IncIntegerState<> DerefBytesState; |
--- |
4001 |
IncIntegerState<> DerefBytesState; |
--- |
| 4002 |
|
--- |
4002 |
|
--- |
| 4003 |
/// Map representing for accessed memory offsets and sizes. |
--- |
4003 |
/// Map representing for accessed memory offsets and sizes. |
--- |
| 4004 |
/// A key is Offset and a value is size. |
--- |
4004 |
/// A key is Offset and a value is size. |
--- |
| 4005 |
/// If there is a load/store instruction something like, |
--- |
4005 |
/// If there is a load/store instruction something like, |
--- |
| 4006 |
/// p[offset] = v; |
--- |
4006 |
/// p[offset] = v; |
--- |
| 4007 |
/// (offset, sizeof(v)) will be inserted to this map. |
--- |
4007 |
/// (offset, sizeof(v)) will be inserted to this map. |
--- |
| 4008 |
/// std::map is used because we want to iterate keys in ascending order. |
--- |
4008 |
/// std::map is used because we want to iterate keys in ascending order. |
--- |
| 4009 |
std::map AccessedBytesMap; |
--- |
4009 |
std::map AccessedBytesMap; |
--- |
| 4010 |
|
--- |
4010 |
|
--- |
| 4011 |
/// Helper function to calculate dereferenceable bytes from current known |
--- |
4011 |
/// Helper function to calculate dereferenceable bytes from current known |
--- |
| 4012 |
/// bytes and accessed bytes. |
--- |
4012 |
/// bytes and accessed bytes. |
--- |
| 4013 |
/// |
--- |
4013 |
/// |
--- |
| 4014 |
/// int f(int *A){ |
--- |
4014 |
/// int f(int *A){ |
--- |
| 4015 |
/// *A = 0; |
--- |
4015 |
/// *A = 0; |
--- |
| 4016 |
/// *(A+2) = 2; |
--- |
4016 |
/// *(A+2) = 2; |
--- |
| 4017 |
/// *(A+1) = 1; |
--- |
4017 |
/// *(A+1) = 1; |
--- |
| 4018 |
/// *(A+10) = 10; |
--- |
4018 |
/// *(A+10) = 10; |
--- |
| 4019 |
/// } |
--- |
4019 |
/// } |
--- |
| 4020 |
/// ``` |
--- |
4020 |
/// ``` |
--- |
| 4021 |
/// In that case, AccessedBytesMap is `{0:4, 4:4, 8:4, 40:4}`. |
--- |
4021 |
/// In that case, AccessedBytesMap is `{0:4, 4:4, 8:4, 40:4}`. |
--- |
| 4022 |
/// AccessedBytesMap is std::map so it is iterated in accending order on |
--- |
4022 |
/// AccessedBytesMap is std::map so it is iterated in accending order on |
--- |
| 4023 |
/// key(Offset). So KnownBytes will be updated like this: |
--- |
4023 |
/// key(Offset). So KnownBytes will be updated like this: |
--- |
| 4024 |
/// |
--- |
4024 |
/// |
--- |
| 4025 |
/// |Access | KnownBytes |
--- |
4025 |
/// |Access | KnownBytes |
--- |
| 4026 |
/// |(0, 4)| 0 -> 4 |
--- |
4026 |
/// |(0, 4)| 0 -> 4 |
--- |
| 4027 |
/// |(4, 4)| 4 -> 8 |
--- |
4027 |
/// |(4, 4)| 4 -> 8 |
--- |
| 4028 |
/// |(8, 4)| 8 -> 12 |
--- |
4028 |
/// |(8, 4)| 8 -> 12 |
--- |
| 4029 |
/// |(40, 4) | 12 (break) |
--- |
4029 |
/// |(40, 4) | 12 (break) |
--- |
| 4030 |
void computeKnownDerefBytesFromAccessedMap() { |
--- |
4030 |
void computeKnownDerefBytesFromAccessedMap() { |
--- |
| 4031 |
int64_t KnownBytes = DerefBytesState.getKnown(); |
--- |
4031 |
int64_t KnownBytes = DerefBytesState.getKnown(); |
--- |
| 4032 |
for (auto &Access : AccessedBytesMap) { |
--- |
4032 |
for (auto &Access : AccessedBytesMap) { |
--- |
| 4033 |
if (KnownBytes < Access.first) |
--- |
4033 |
if (KnownBytes < Access.first) |
--- |
| 4034 |
break; |
--- |
4034 |
break; |
--- |
| 4035 |
KnownBytes = std::max(KnownBytes, Access.first + (int64_t)Access.second); |
--- |
4035 |
KnownBytes = std::max(KnownBytes, Access.first + (int64_t)Access.second); |
--- |
| 4036 |
} |
--- |
4036 |
} |
--- |
| 4037 |
|
--- |
4037 |
|
--- |
| 4038 |
DerefBytesState.takeKnownMaximum(KnownBytes); |
--- |
4038 |
DerefBytesState.takeKnownMaximum(KnownBytes); |
--- |
| 4039 |
} |
--- |
4039 |
} |
--- |
| 4040 |
|
--- |
4040 |
|
--- |
| 4041 |
/// State representing that whether the value is globaly dereferenceable. |
--- |
4041 |
/// State representing that whether the value is globaly dereferenceable. |
--- |
| 4042 |
BooleanState GlobalState; |
--- |
4042 |
BooleanState GlobalState; |
--- |
| 4043 |
|
--- |
4043 |
|
--- |
| 4044 |
/// See AbstractState::isValidState() |
--- |
4044 |
/// See AbstractState::isValidState() |
--- |
| 4045 |
bool isValidState() const override { return DerefBytesState.isValidState(); } |
--- |
4045 |
bool isValidState() const override { return DerefBytesState.isValidState(); } |
--- |
| 4046 |
|
--- |
4046 |
|
--- |
| 4047 |
/// See AbstractState::isAtFixpoint() |
--- |
4047 |
/// See AbstractState::isAtFixpoint() |
--- |
| 4048 |
bool isAtFixpoint() const override { |
--- |
4048 |
bool isAtFixpoint() const override { |
--- |
| 4049 |
return !isValidState() || |
--- |
4049 |
return !isValidState() || |
--- |
| 4050 |
(DerefBytesState.isAtFixpoint() && GlobalState.isAtFixpoint()); |
--- |
4050 |
(DerefBytesState.isAtFixpoint() && GlobalState.isAtFixpoint()); |
--- |
| 4051 |
} |
--- |
4051 |
} |
--- |
| 4052 |
|
--- |
4052 |
|
--- |
| 4053 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
4053 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
| 4054 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
4054 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
| 4055 |
DerefBytesState.indicateOptimisticFixpoint(); |
--- |
4055 |
DerefBytesState.indicateOptimisticFixpoint(); |
--- |
| 4056 |
GlobalState.indicateOptimisticFixpoint(); |
--- |
4056 |
GlobalState.indicateOptimisticFixpoint(); |
--- |
| 4057 |
return ChangeStatus::UNCHANGED; |
--- |
4057 |
return ChangeStatus::UNCHANGED; |
--- |
| 4058 |
} |
--- |
4058 |
} |
--- |
| 4059 |
|
--- |
4059 |
|
--- |
| 4060 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
4060 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
| 4061 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
4061 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
| 4062 |
DerefBytesState.indicatePessimisticFixpoint(); |
--- |
4062 |
DerefBytesState.indicatePessimisticFixpoint(); |
--- |
| 4063 |
GlobalState.indicatePessimisticFixpoint(); |
--- |
4063 |
GlobalState.indicatePessimisticFixpoint(); |
--- |
| 4064 |
return ChangeStatus::CHANGED; |
--- |
4064 |
return ChangeStatus::CHANGED; |
--- |
| 4065 |
} |
--- |
4065 |
} |
--- |
| 4066 |
|
--- |
4066 |
|
--- |
| 4067 |
/// Update known dereferenceable bytes. |
--- |
4067 |
/// Update known dereferenceable bytes. |
--- |
| 4068 |
void takeKnownDerefBytesMaximum(uint64_t Bytes) { |
--- |
4068 |
void takeKnownDerefBytesMaximum(uint64_t Bytes) { |
--- |
| 4069 |
DerefBytesState.takeKnownMaximum(Bytes); |
--- |
4069 |
DerefBytesState.takeKnownMaximum(Bytes); |
--- |
| 4070 |
|
--- |
4070 |
|
--- |
| 4071 |
// Known bytes might increase. |
--- |
4071 |
// Known bytes might increase. |
--- |
| 4072 |
computeKnownDerefBytesFromAccessedMap(); |
--- |
4072 |
computeKnownDerefBytesFromAccessedMap(); |
--- |
| 4073 |
} |
--- |
4073 |
} |
--- |
| 4074 |
|
--- |
4074 |
|
--- |
| 4075 |
/// Update assumed dereferenceable bytes. |
--- |
4075 |
/// Update assumed dereferenceable bytes. |
--- |
| 4076 |
void takeAssumedDerefBytesMinimum(uint64_t Bytes) { |
--- |
4076 |
void takeAssumedDerefBytesMinimum(uint64_t Bytes) { |
--- |
| 4077 |
DerefBytesState.takeAssumedMinimum(Bytes); |
--- |
4077 |
DerefBytesState.takeAssumedMinimum(Bytes); |
--- |
| 4078 |
} |
--- |
4078 |
} |
--- |
| 4079 |
|
--- |
4079 |
|
--- |
| 4080 |
/// Add accessed bytes to the map. |
--- |
4080 |
/// Add accessed bytes to the map. |
--- |
| 4081 |
void addAccessedBytes(int64_t Offset, uint64_t Size) { |
--- |
4081 |
void addAccessedBytes(int64_t Offset, uint64_t Size) { |
--- |
| 4082 |
uint64_t &AccessedBytes = AccessedBytesMap[Offset]; |
--- |
4082 |
uint64_t &AccessedBytes = AccessedBytesMap[Offset]; |
--- |
| 4083 |
AccessedBytes = std::max(AccessedBytes, Size); |
--- |
4083 |
AccessedBytes = std::max(AccessedBytes, Size); |
--- |
| 4084 |
|
--- |
4084 |
|
--- |
| 4085 |
// Known bytes might increase. |
--- |
4085 |
// Known bytes might increase. |
--- |
| 4086 |
computeKnownDerefBytesFromAccessedMap(); |
--- |
4086 |
computeKnownDerefBytesFromAccessedMap(); |
--- |
| 4087 |
} |
--- |
4087 |
} |
--- |
| 4088 |
|
--- |
4088 |
|
--- |
| 4089 |
/// Equality for DerefState. |
--- |
4089 |
/// Equality for DerefState. |
--- |
| 4090 |
bool operator==(const DerefState &R) const { |
--- |
4090 |
bool operator==(const DerefState &R) const { |
--- |
| 4091 |
return this->DerefBytesState == R.DerefBytesState && |
--- |
4091 |
return this->DerefBytesState == R.DerefBytesState && |
--- |
| 4092 |
this->GlobalState == R.GlobalState; |
--- |
4092 |
this->GlobalState == R.GlobalState; |
--- |
| 4093 |
} |
--- |
4093 |
} |
--- |
| 4094 |
|
--- |
4094 |
|
--- |
| 4095 |
/// Inequality for DerefState. |
--- |
4095 |
/// Inequality for DerefState. |
--- |
| 4096 |
bool operator!=(const DerefState &R) const { return !(*this == R); } |
--- |
4096 |
bool operator!=(const DerefState &R) const { return !(*this == R); } |
--- |
| 4097 |
|
--- |
4097 |
|
--- |
| 4098 |
/// See IntegerStateBase::operator^= |
--- |
4098 |
/// See IntegerStateBase::operator^= |
--- |
| 4099 |
DerefState operator^=(const DerefState &R) { |
--- |
4099 |
DerefState operator^=(const DerefState &R) { |
--- |
| 4100 |
DerefBytesState ^= R.DerefBytesState; |
--- |
4100 |
DerefBytesState ^= R.DerefBytesState; |
--- |
| 4101 |
GlobalState ^= R.GlobalState; |
--- |
4101 |
GlobalState ^= R.GlobalState; |
--- |
| 4102 |
return *this; |
--- |
4102 |
return *this; |
--- |
| 4103 |
} |
--- |
4103 |
} |
--- |
| 4104 |
|
--- |
4104 |
|
--- |
| 4105 |
/// See IntegerStateBase::operator+= |
--- |
4105 |
/// See IntegerStateBase::operator+= |
--- |
| 4106 |
DerefState operator+=(const DerefState &R) { |
--- |
4106 |
DerefState operator+=(const DerefState &R) { |
--- |
| 4107 |
DerefBytesState += R.DerefBytesState; |
--- |
4107 |
DerefBytesState += R.DerefBytesState; |
--- |
| 4108 |
GlobalState += R.GlobalState; |
--- |
4108 |
GlobalState += R.GlobalState; |
--- |
| 4109 |
return *this; |
--- |
4109 |
return *this; |
--- |
| 4110 |
} |
--- |
4110 |
} |
--- |
| 4111 |
|
--- |
4111 |
|
--- |
| 4112 |
/// See IntegerStateBase::operator&= |
--- |
4112 |
/// See IntegerStateBase::operator&= |
--- |
| 4113 |
DerefState operator&=(const DerefState &R) { |
--- |
4113 |
DerefState operator&=(const DerefState &R) { |
--- |
| 4114 |
DerefBytesState &= R.DerefBytesState; |
--- |
4114 |
DerefBytesState &= R.DerefBytesState; |
--- |
| 4115 |
GlobalState &= R.GlobalState; |
--- |
4115 |
GlobalState &= R.GlobalState; |
--- |
| 4116 |
return *this; |
--- |
4116 |
return *this; |
--- |
| 4117 |
} |
--- |
4117 |
} |
--- |
| 4118 |
|
--- |
4118 |
|
--- |
| 4119 |
/// See IntegerStateBase::operator|= |
--- |
4119 |
/// See IntegerStateBase::operator|= |
--- |
| 4120 |
DerefState operator|=(const DerefState &R) { |
--- |
4120 |
DerefState operator|=(const DerefState &R) { |
--- |
| 4121 |
DerefBytesState |= R.DerefBytesState; |
--- |
4121 |
DerefBytesState |= R.DerefBytesState; |
--- |
| 4122 |
GlobalState |= R.GlobalState; |
--- |
4122 |
GlobalState |= R.GlobalState; |
--- |
| 4123 |
return *this; |
--- |
4123 |
return *this; |
--- |
| 4124 |
} |
--- |
4124 |
} |
--- |
| 4125 |
}; |
--- |
4125 |
}; |
--- |
| 4126 |
|
--- |
4126 |
|
--- |
| 4127 |
/// An abstract interface for all dereferenceable attribute. |
--- |
4127 |
/// An abstract interface for all dereferenceable attribute. |
--- |
| 4128 |
struct AADereferenceable |
--- |
4128 |
struct AADereferenceable |
--- |
| 4129 |
: public IRAttribute
| --- |
4129 |
: public IRAttribute
| --- |
| |
| 4130 |
StateWrapper, |
--- |
4130 |
StateWrapper, |
--- |
| 4131 |
AADereferenceable> { |
--- |
4131 |
AADereferenceable> { |
--- |
| 4132 |
AADereferenceable(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
4132 |
AADereferenceable(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 4133 |
|
--- |
4133 |
|
--- |
| 4134 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4134 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4135 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
4135 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 4136 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
4136 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 4137 |
return false; |
0 |
4137 |
return false; |
0 |
| 4138 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
4138 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 4139 |
} |
--- |
4139 |
} |
--- |
| 4140 |
|
--- |
4140 |
|
--- |
| 4141 |
/// Return true if we assume that underlying value is |
--- |
4141 |
/// Return true if we assume that underlying value is |
--- |
| 4142 |
/// dereferenceable(_or_null) globally. |
--- |
4142 |
/// dereferenceable(_or_null) globally. |
--- |
| 4143 |
bool isAssumedGlobal() const { return GlobalState.getAssumed(); } |
--- |
4143 |
bool isAssumedGlobal() const { return GlobalState.getAssumed(); } |
--- |
| 4144 |
|
--- |
4144 |
|
--- |
| 4145 |
/// Return true if we know that underlying value is |
--- |
4145 |
/// Return true if we know that underlying value is |
--- |
| 4146 |
/// dereferenceable(_or_null) globally. |
--- |
4146 |
/// dereferenceable(_or_null) globally. |
--- |
| 4147 |
bool isKnownGlobal() const { return GlobalState.getKnown(); } |
--- |
4147 |
bool isKnownGlobal() const { return GlobalState.getKnown(); } |
--- |
| 4148 |
|
--- |
4148 |
|
--- |
| 4149 |
/// Return assumed dereferenceable bytes. |
--- |
4149 |
/// Return assumed dereferenceable bytes. |
--- |
| 4150 |
uint32_t getAssumedDereferenceableBytes() const { |
--- |
4150 |
uint32_t getAssumedDereferenceableBytes() const { |
--- |
| 4151 |
return DerefBytesState.getAssumed(); |
--- |
4151 |
return DerefBytesState.getAssumed(); |
--- |
| 4152 |
} |
--- |
4152 |
} |
--- |
| 4153 |
|
--- |
4153 |
|
--- |
| 4154 |
/// Return known dereferenceable bytes. |
--- |
4154 |
/// Return known dereferenceable bytes. |
--- |
| 4155 |
uint32_t getKnownDereferenceableBytes() const { |
--- |
4155 |
uint32_t getKnownDereferenceableBytes() const { |
--- |
| 4156 |
return DerefBytesState.getKnown(); |
--- |
4156 |
return DerefBytesState.getKnown(); |
--- |
| 4157 |
} |
--- |
4157 |
} |
--- |
| 4158 |
|
--- |
4158 |
|
--- |
| 4159 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4159 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4160 |
static AADereferenceable &createForPosition(const IRPosition &IRP, |
--- |
4160 |
static AADereferenceable &createForPosition(const IRPosition &IRP, |
--- |
| 4161 |
Attributor &A); |
--- |
4161 |
Attributor &A); |
--- |
| 4162 |
|
--- |
4162 |
|
--- |
| 4163 |
/// See AbstractAttribute::getName() |
--- |
4163 |
/// See AbstractAttribute::getName() |
--- |
| 4164 |
const std::string getName() const override { return "AADereferenceable"; } |
--- |
4164 |
const std::string getName() const override { return "AADereferenceable"; } |
--- |
| 4165 |
|
--- |
4165 |
|
--- |
| 4166 |
/// See AbstractAttribute::getIdAddr() |
--- |
4166 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4167 |
const char *getIdAddr() const override { return &ID; } |
--- |
4167 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4168 |
|
--- |
4168 |
|
--- |
| 4169 |
/// This function should return true if the type of the \p AA is |
--- |
4169 |
/// This function should return true if the type of the \p AA is |
--- |
| 4170 |
/// AADereferenceable |
--- |
4170 |
/// AADereferenceable |
--- |
| 4171 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4171 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4172 |
return (AA->getIdAddr() == &ID); |
--- |
4172 |
return (AA->getIdAddr() == &ID); |
--- |
| 4173 |
} |
--- |
4173 |
} |
--- |
| 4174 |
|
--- |
4174 |
|
--- |
| 4175 |
/// Unique ID (due to the unique address) |
--- |
4175 |
/// Unique ID (due to the unique address) |
--- |
| 4176 |
static const char ID; |
--- |
4176 |
static const char ID; |
--- |
| 4177 |
}; |
--- |
4177 |
}; |
--- |
| 4178 |
|
--- |
4178 |
|
--- |
| 4179 |
using AAAlignmentStateType = |
--- |
4179 |
using AAAlignmentStateType = |
--- |
| 4180 |
IncIntegerState; |
--- |
4180 |
IncIntegerState; |
--- |
| 4181 |
/// An abstract interface for all align attributes. |
--- |
4181 |
/// An abstract interface for all align attributes. |
--- |
| 4182 |
struct AAAlign |
--- |
4182 |
struct AAAlign |
--- |
| 4183 |
: public IRAttribute
| --- |
4183 |
: public IRAttribute
| --- |
| |
| 4184 |
StateWrapper, |
--- |
4184 |
StateWrapper, |
--- |
| 4185 |
AAAlign> { |
--- |
4185 |
AAAlign> { |
--- |
| 4186 |
AAAlign(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
4186 |
AAAlign(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 4187 |
|
--- |
4187 |
|
--- |
| 4188 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4188 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4189 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
4189 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 4190 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
4190 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 4191 |
return false; |
0 |
4191 |
return false; |
0 |
| 4192 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
4192 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 4193 |
} |
--- |
4193 |
} |
--- |
| 4194 |
|
--- |
4194 |
|
--- |
| 4195 |
/// Return assumed alignment. |
--- |
4195 |
/// Return assumed alignment. |
--- |
| 4196 |
Align getAssumedAlign() const { return Align(getAssumed()); } |
--- |
4196 |
Align getAssumedAlign() const { return Align(getAssumed()); } |
--- |
| 4197 |
|
--- |
4197 |
|
--- |
| 4198 |
/// Return known alignment. |
--- |
4198 |
/// Return known alignment. |
--- |
| 4199 |
Align getKnownAlign() const { return Align(getKnown()); } |
--- |
4199 |
Align getKnownAlign() const { return Align(getKnown()); } |
--- |
| 4200 |
|
--- |
4200 |
|
--- |
| 4201 |
/// See AbstractAttribute::getName() |
--- |
4201 |
/// See AbstractAttribute::getName() |
--- |
| 4202 |
const std::string getName() const override { return "AAAlign"; } |
--- |
4202 |
const std::string getName() const override { return "AAAlign"; } |
--- |
| 4203 |
|
--- |
4203 |
|
--- |
| 4204 |
/// See AbstractAttribute::getIdAddr() |
--- |
4204 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4205 |
const char *getIdAddr() const override { return &ID; } |
--- |
4205 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4206 |
|
--- |
4206 |
|
--- |
| 4207 |
/// This function should return true if the type of the \p AA is AAAlign |
--- |
4207 |
/// This function should return true if the type of the \p AA is AAAlign |
--- |
| 4208 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4208 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4209 |
return (AA->getIdAddr() == &ID); |
--- |
4209 |
return (AA->getIdAddr() == &ID); |
--- |
| 4210 |
} |
--- |
4210 |
} |
--- |
| 4211 |
|
--- |
4211 |
|
--- |
| 4212 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4212 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4213 |
static AAAlign &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
4213 |
static AAAlign &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 4214 |
|
--- |
4214 |
|
--- |
| 4215 |
/// Unique ID (due to the unique address) |
--- |
4215 |
/// Unique ID (due to the unique address) |
--- |
| 4216 |
static const char ID; |
--- |
4216 |
static const char ID; |
--- |
| 4217 |
}; |
--- |
4217 |
}; |
--- |
| 4218 |
|
--- |
4218 |
|
--- |
| 4219 |
/// An abstract interface to track if a value leaves it's defining function |
--- |
4219 |
/// An abstract interface to track if a value leaves it's defining function |
--- |
| 4220 |
/// instance. |
--- |
4220 |
/// instance. |
--- |
| 4221 |
/// TODO: We should make it a ternary AA tracking uniqueness, and uniqueness |
--- |
4221 |
/// TODO: We should make it a ternary AA tracking uniqueness, and uniqueness |
--- |
| 4222 |
/// wrt. the Attributor analysis separately. |
--- |
4222 |
/// wrt. the Attributor analysis separately. |
--- |
| 4223 |
struct AAInstanceInfo : public StateWrapper { |
--- |
4223 |
struct AAInstanceInfo : public StateWrapper { |
--- |
| 4224 |
AAInstanceInfo(const IRPosition &IRP, Attributor &A) |
--- |
4224 |
AAInstanceInfo(const IRPosition &IRP, Attributor &A) |
--- |
| 4225 |
: StateWrapper(IRP) {} |
--- |
4225 |
: StateWrapper(IRP) {} |
--- |
| 4226 |
|
--- |
4226 |
|
--- |
| 4227 |
/// Return true if we know that the underlying value is unique in its scope |
--- |
4227 |
/// Return true if we know that the underlying value is unique in its scope |
--- |
| 4228 |
/// wrt. the Attributor analysis. That means it might not be unique but we can |
--- |
4228 |
/// wrt. the Attributor analysis. That means it might not be unique but we can |
--- |
| 4229 |
/// still use pointer equality without risking to represent two instances with |
--- |
4229 |
/// still use pointer equality without risking to represent two instances with |
--- |
| 4230 |
/// one `llvm::Value`. |
--- |
4230 |
/// one `llvm::Value`. |
--- |
| 4231 |
bool isKnownUniqueForAnalysis() const { return isKnown(); } |
--- |
4231 |
bool isKnownUniqueForAnalysis() const { return isKnown(); } |
--- |
| 4232 |
|
--- |
4232 |
|
--- |
| 4233 |
/// Return true if we assume that the underlying value is unique in its scope |
--- |
4233 |
/// Return true if we assume that the underlying value is unique in its scope |
--- |
| 4234 |
/// wrt. the Attributor analysis. That means it might not be unique but we can |
--- |
4234 |
/// wrt. the Attributor analysis. That means it might not be unique but we can |
--- |
| 4235 |
/// still use pointer equality without risking to represent two instances with |
--- |
4235 |
/// still use pointer equality without risking to represent two instances with |
--- |
| 4236 |
/// one `llvm::Value`. |
--- |
4236 |
/// one `llvm::Value`. |
--- |
| 4237 |
bool isAssumedUniqueForAnalysis() const { return isAssumed(); } |
0 |
4237 |
bool isAssumedUniqueForAnalysis() const { return isAssumed(); } |
0 |
| 4238 |
|
--- |
4238 |
|
--- |
| 4239 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4239 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4240 |
static AAInstanceInfo &createForPosition(const IRPosition &IRP, |
--- |
4240 |
static AAInstanceInfo &createForPosition(const IRPosition &IRP, |
--- |
| 4241 |
Attributor &A); |
--- |
4241 |
Attributor &A); |
--- |
| 4242 |
|
--- |
4242 |
|
--- |
| 4243 |
/// See AbstractAttribute::getName() |
--- |
4243 |
/// See AbstractAttribute::getName() |
--- |
| 4244 |
const std::string getName() const override { return "AAInstanceInfo"; } |
--- |
4244 |
const std::string getName() const override { return "AAInstanceInfo"; } |
--- |
| 4245 |
|
--- |
4245 |
|
--- |
| 4246 |
/// See AbstractAttribute::getIdAddr() |
--- |
4246 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4247 |
const char *getIdAddr() const override { return &ID; } |
--- |
4247 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4248 |
|
--- |
4248 |
|
--- |
| 4249 |
/// This function should return true if the type of the \p AA is |
--- |
4249 |
/// This function should return true if the type of the \p AA is |
--- |
| 4250 |
/// AAInstanceInfo |
--- |
4250 |
/// AAInstanceInfo |
--- |
| 4251 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4251 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4252 |
return (AA->getIdAddr() == &ID); |
--- |
4252 |
return (AA->getIdAddr() == &ID); |
--- |
| 4253 |
} |
--- |
4253 |
} |
--- |
| 4254 |
|
--- |
4254 |
|
--- |
| 4255 |
/// Unique ID (due to the unique address) |
--- |
4255 |
/// Unique ID (due to the unique address) |
--- |
| 4256 |
static const char ID; |
--- |
4256 |
static const char ID; |
--- |
| 4257 |
}; |
--- |
4257 |
}; |
--- |
| 4258 |
|
--- |
4258 |
|
--- |
| 4259 |
/// An abstract interface for all nocapture attributes. |
--- |
4259 |
/// An abstract interface for all nocapture attributes. |
--- |
| 4260 |
struct AANoCapture |
--- |
4260 |
struct AANoCapture |
--- |
| 4261 |
: public IRAttribute< |
--- |
4261 |
: public IRAttribute< |
--- |
| 4262 |
Attribute::NoCapture, |
--- |
4262 |
Attribute::NoCapture, |
--- |
| 4263 |
StateWrapper, AbstractAttribute>, |
--- |
4263 |
StateWrapper, AbstractAttribute>, |
--- |
| 4264 |
AANoCapture> { |
--- |
4264 |
AANoCapture> { |
--- |
| 4265 |
AANoCapture(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
4265 |
AANoCapture(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 4266 |
|
--- |
4266 |
|
--- |
| 4267 |
/// See IRAttribute::isImpliedByIR |
--- |
4267 |
/// See IRAttribute::isImpliedByIR |
--- |
| 4268 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
4268 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
| 4269 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
4269 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 4270 |
bool IgnoreSubsumingPositions = false); |
--- |
4270 |
bool IgnoreSubsumingPositions = false); |
--- |
| 4271 |
|
--- |
4271 |
|
--- |
| 4272 |
/// Update \p State according to the capture capabilities of \p F for position |
--- |
4272 |
/// Update \p State according to the capture capabilities of \p F for position |
--- |
| 4273 |
/// \p IRP. |
--- |
4273 |
/// \p IRP. |
--- |
| 4274 |
static void determineFunctionCaptureCapabilities(const IRPosition &IRP, |
--- |
4274 |
static void determineFunctionCaptureCapabilities(const IRPosition &IRP, |
--- |
| 4275 |
const Function &F, |
--- |
4275 |
const Function &F, |
--- |
| 4276 |
BitIntegerState &State); |
--- |
4276 |
BitIntegerState &State); |
--- |
| 4277 |
|
--- |
4277 |
|
--- |
| 4278 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4278 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4279 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
4279 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 4280 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
4280 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 4281 |
return false; |
0 |
4281 |
return false; |
0 |
| 4282 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
4282 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 4283 |
} |
--- |
4283 |
} |
--- |
| 4284 |
|
--- |
4284 |
|
--- |
| 4285 |
/// State encoding bits. A set bit in the state means the property holds. |
--- |
4285 |
/// State encoding bits. A set bit in the state means the property holds. |
--- |
| 4286 |
/// NO_CAPTURE is the best possible state, 0 the worst possible state. |
--- |
4286 |
/// NO_CAPTURE is the best possible state, 0 the worst possible state. |
--- |
| 4287 |
enum { |
--- |
4287 |
enum { |
--- |
| 4288 |
NOT_CAPTURED_IN_MEM = 1 << 0, |
--- |
4288 |
NOT_CAPTURED_IN_MEM = 1 << 0, |
--- |
| 4289 |
NOT_CAPTURED_IN_INT = 1 << 1, |
--- |
4289 |
NOT_CAPTURED_IN_INT = 1 << 1, |
--- |
| 4290 |
NOT_CAPTURED_IN_RET = 1 << 2, |
--- |
4290 |
NOT_CAPTURED_IN_RET = 1 << 2, |
--- |
| 4291 |
|
--- |
4291 |
|
--- |
| 4292 |
/// If we do not capture the value in memory or through integers we can only |
--- |
4292 |
/// If we do not capture the value in memory or through integers we can only |
--- |
| 4293 |
/// communicate it back as a derived pointer. |
--- |
4293 |
/// communicate it back as a derived pointer. |
--- |
| 4294 |
NO_CAPTURE_MAYBE_RETURNED = NOT_CAPTURED_IN_MEM | NOT_CAPTURED_IN_INT, |
--- |
4294 |
NO_CAPTURE_MAYBE_RETURNED = NOT_CAPTURED_IN_MEM | NOT_CAPTURED_IN_INT, |
--- |
| 4295 |
|
--- |
4295 |
|
--- |
| 4296 |
/// If we do not capture the value in memory, through integers, or as a |
--- |
4296 |
/// If we do not capture the value in memory, through integers, or as a |
--- |
| 4297 |
/// derived pointer we know it is not captured. |
--- |
4297 |
/// derived pointer we know it is not captured. |
--- |
| 4298 |
NO_CAPTURE = |
--- |
4298 |
NO_CAPTURE = |
--- |
| 4299 |
NOT_CAPTURED_IN_MEM | NOT_CAPTURED_IN_INT | NOT_CAPTURED_IN_RET, |
--- |
4299 |
NOT_CAPTURED_IN_MEM | NOT_CAPTURED_IN_INT | NOT_CAPTURED_IN_RET, |
--- |
| 4300 |
}; |
--- |
4300 |
}; |
--- |
| 4301 |
|
--- |
4301 |
|
--- |
| 4302 |
/// Return true if we know that the underlying value is not captured in its |
--- |
4302 |
/// Return true if we know that the underlying value is not captured in its |
--- |
| 4303 |
/// respective scope. |
--- |
4303 |
/// respective scope. |
--- |
| 4304 |
bool isKnownNoCapture() const { return isKnown(NO_CAPTURE); } |
--- |
4304 |
bool isKnownNoCapture() const { return isKnown(NO_CAPTURE); } |
--- |
| 4305 |
|
--- |
4305 |
|
--- |
| 4306 |
/// Return true if we assume that the underlying value is not captured in its |
--- |
4306 |
/// Return true if we assume that the underlying value is not captured in its |
--- |
| 4307 |
/// respective scope. |
--- |
4307 |
/// respective scope. |
--- |
| 4308 |
bool isAssumedNoCapture() const { return isAssumed(NO_CAPTURE); } |
--- |
4308 |
bool isAssumedNoCapture() const { return isAssumed(NO_CAPTURE); } |
--- |
| 4309 |
|
--- |
4309 |
|
--- |
| 4310 |
/// Return true if we know that the underlying value is not captured in its |
--- |
4310 |
/// Return true if we know that the underlying value is not captured in its |
--- |
| 4311 |
/// respective scope but we allow it to escape through a "return". |
--- |
4311 |
/// respective scope but we allow it to escape through a "return". |
--- |
| 4312 |
bool isKnownNoCaptureMaybeReturned() const { |
--- |
4312 |
bool isKnownNoCaptureMaybeReturned() const { |
--- |
| 4313 |
return isKnown(NO_CAPTURE_MAYBE_RETURNED); |
--- |
4313 |
return isKnown(NO_CAPTURE_MAYBE_RETURNED); |
--- |
| 4314 |
} |
--- |
4314 |
} |
--- |
| 4315 |
|
--- |
4315 |
|
--- |
| 4316 |
/// Return true if we assume that the underlying value is not captured in its |
--- |
4316 |
/// Return true if we assume that the underlying value is not captured in its |
--- |
| 4317 |
/// respective scope but we allow it to escape through a "return". |
--- |
4317 |
/// respective scope but we allow it to escape through a "return". |
--- |
| 4318 |
bool isAssumedNoCaptureMaybeReturned() const { |
--- |
4318 |
bool isAssumedNoCaptureMaybeReturned() const { |
--- |
| 4319 |
return isAssumed(NO_CAPTURE_MAYBE_RETURNED); |
--- |
4319 |
return isAssumed(NO_CAPTURE_MAYBE_RETURNED); |
--- |
| 4320 |
} |
--- |
4320 |
} |
--- |
| 4321 |
|
--- |
4321 |
|
--- |
| 4322 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4322 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4323 |
static AANoCapture &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
4323 |
static AANoCapture &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 4324 |
|
--- |
4324 |
|
--- |
| 4325 |
/// See AbstractAttribute::getName() |
--- |
4325 |
/// See AbstractAttribute::getName() |
--- |
| 4326 |
const std::string getName() const override { return "AANoCapture"; } |
--- |
4326 |
const std::string getName() const override { return "AANoCapture"; } |
--- |
| 4327 |
|
--- |
4327 |
|
--- |
| 4328 |
/// See AbstractAttribute::getIdAddr() |
--- |
4328 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4329 |
const char *getIdAddr() const override { return &ID; } |
--- |
4329 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4330 |
|
--- |
4330 |
|
--- |
| 4331 |
/// This function should return true if the type of the \p AA is AANoCapture |
--- |
4331 |
/// This function should return true if the type of the \p AA is AANoCapture |
--- |
| 4332 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4332 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4333 |
return (AA->getIdAddr() == &ID); |
--- |
4333 |
return (AA->getIdAddr() == &ID); |
--- |
| 4334 |
} |
--- |
4334 |
} |
--- |
| 4335 |
|
--- |
4335 |
|
--- |
| 4336 |
/// Unique ID (due to the unique address) |
--- |
4336 |
/// Unique ID (due to the unique address) |
--- |
| 4337 |
static const char ID; |
--- |
4337 |
static const char ID; |
--- |
| 4338 |
}; |
--- |
4338 |
}; |
--- |
| 4339 |
|
--- |
4339 |
|
--- |
| 4340 |
struct ValueSimplifyStateType : public AbstractState { |
--- |
4340 |
struct ValueSimplifyStateType : public AbstractState { |
--- |
| 4341 |
|
--- |
4341 |
|
--- |
| 4342 |
ValueSimplifyStateType(Type *Ty) : Ty(Ty) {} |
--- |
4342 |
ValueSimplifyStateType(Type *Ty) : Ty(Ty) {} |
--- |
| 4343 |
|
--- |
4343 |
|
--- |
| 4344 |
static ValueSimplifyStateType getBestState(Type *Ty) { |
--- |
4344 |
static ValueSimplifyStateType getBestState(Type *Ty) { |
--- |
| 4345 |
return ValueSimplifyStateType(Ty); |
--- |
4345 |
return ValueSimplifyStateType(Ty); |
--- |
| 4346 |
} |
--- |
4346 |
} |
--- |
| 4347 |
static ValueSimplifyStateType getBestState(const ValueSimplifyStateType &VS) { |
--- |
4347 |
static ValueSimplifyStateType getBestState(const ValueSimplifyStateType &VS) { |
--- |
| 4348 |
return getBestState(VS.Ty); |
--- |
4348 |
return getBestState(VS.Ty); |
--- |
| 4349 |
} |
--- |
4349 |
} |
--- |
| 4350 |
|
--- |
4350 |
|
--- |
| 4351 |
/// Return the worst possible representable state. |
--- |
4351 |
/// Return the worst possible representable state. |
--- |
| 4352 |
static ValueSimplifyStateType getWorstState(Type *Ty) { |
--- |
4352 |
static ValueSimplifyStateType getWorstState(Type *Ty) { |
--- |
| 4353 |
ValueSimplifyStateType DS(Ty); |
--- |
4353 |
ValueSimplifyStateType DS(Ty); |
--- |
| 4354 |
DS.indicatePessimisticFixpoint(); |
--- |
4354 |
DS.indicatePessimisticFixpoint(); |
--- |
| 4355 |
return DS; |
--- |
4355 |
return DS; |
--- |
| 4356 |
} |
--- |
4356 |
} |
--- |
| 4357 |
static ValueSimplifyStateType |
--- |
4357 |
static ValueSimplifyStateType |
--- |
| 4358 |
getWorstState(const ValueSimplifyStateType &VS) { |
--- |
4358 |
getWorstState(const ValueSimplifyStateType &VS) { |
--- |
| 4359 |
return getWorstState(VS.Ty); |
--- |
4359 |
return getWorstState(VS.Ty); |
--- |
| 4360 |
} |
--- |
4360 |
} |
--- |
| 4361 |
|
--- |
4361 |
|
--- |
| 4362 |
/// See AbstractState::isValidState(...) |
--- |
4362 |
/// See AbstractState::isValidState(...) |
--- |
| 4363 |
bool isValidState() const override { return BS.isValidState(); } |
--- |
4363 |
bool isValidState() const override { return BS.isValidState(); } |
--- |
| 4364 |
|
--- |
4364 |
|
--- |
| 4365 |
/// See AbstractState::isAtFixpoint(...) |
--- |
4365 |
/// See AbstractState::isAtFixpoint(...) |
--- |
| 4366 |
bool isAtFixpoint() const override { return BS.isAtFixpoint(); } |
--- |
4366 |
bool isAtFixpoint() const override { return BS.isAtFixpoint(); } |
--- |
| 4367 |
|
--- |
4367 |
|
--- |
| 4368 |
/// Return the assumed state encoding. |
--- |
4368 |
/// Return the assumed state encoding. |
--- |
| 4369 |
ValueSimplifyStateType getAssumed() { return *this; } |
--- |
4369 |
ValueSimplifyStateType getAssumed() { return *this; } |
--- |
| 4370 |
const ValueSimplifyStateType &getAssumed() const { return *this; } |
--- |
4370 |
const ValueSimplifyStateType &getAssumed() const { return *this; } |
--- |
| 4371 |
|
--- |
4371 |
|
--- |
| 4372 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
4372 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
| 4373 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
4373 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
| 4374 |
return BS.indicatePessimisticFixpoint(); |
--- |
4374 |
return BS.indicatePessimisticFixpoint(); |
--- |
| 4375 |
} |
--- |
4375 |
} |
--- |
| 4376 |
|
--- |
4376 |
|
--- |
| 4377 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
4377 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
| 4378 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
4378 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
| 4379 |
return BS.indicateOptimisticFixpoint(); |
--- |
4379 |
return BS.indicateOptimisticFixpoint(); |
--- |
| 4380 |
} |
--- |
4380 |
} |
--- |
| 4381 |
|
--- |
4381 |
|
--- |
| 4382 |
/// "Clamp" this state with \p PVS. |
--- |
4382 |
/// "Clamp" this state with \p PVS. |
--- |
| 4383 |
ValueSimplifyStateType operator^=(const ValueSimplifyStateType &VS) { |
--- |
4383 |
ValueSimplifyStateType operator^=(const ValueSimplifyStateType &VS) { |
--- |
| 4384 |
BS ^= VS.BS; |
--- |
4384 |
BS ^= VS.BS; |
--- |
| 4385 |
unionAssumed(VS.SimplifiedAssociatedValue); |
--- |
4385 |
unionAssumed(VS.SimplifiedAssociatedValue); |
--- |
| 4386 |
return *this; |
--- |
4386 |
return *this; |
--- |
| 4387 |
} |
--- |
4387 |
} |
--- |
| 4388 |
|
--- |
4388 |
|
--- |
| 4389 |
bool operator==(const ValueSimplifyStateType &RHS) const { |
--- |
4389 |
bool operator==(const ValueSimplifyStateType &RHS) const { |
--- |
| 4390 |
if (isValidState() != RHS.isValidState()) |
--- |
4390 |
if (isValidState() != RHS.isValidState()) |
--- |
| 4391 |
return false; |
--- |
4391 |
return false; |
--- |
| 4392 |
if (!isValidState() && !RHS.isValidState()) |
--- |
4392 |
if (!isValidState() && !RHS.isValidState()) |
--- |
| 4393 |
return true; |
--- |
4393 |
return true; |
--- |
| 4394 |
return SimplifiedAssociatedValue == RHS.SimplifiedAssociatedValue; |
--- |
4394 |
return SimplifiedAssociatedValue == RHS.SimplifiedAssociatedValue; |
--- |
| 4395 |
} |
--- |
4395 |
} |
--- |
| 4396 |
|
--- |
4396 |
|
--- |
| 4397 |
protected: |
--- |
4397 |
protected: |
--- |
| 4398 |
/// The type of the original value. |
--- |
4398 |
/// The type of the original value. |
--- |
| 4399 |
Type *Ty; |
--- |
4399 |
Type *Ty; |
--- |
| 4400 |
|
--- |
4400 |
|
--- |
| 4401 |
/// Merge \p Other into the currently assumed simplified value |
--- |
4401 |
/// Merge \p Other into the currently assumed simplified value |
--- |
| 4402 |
bool unionAssumed(std::optional Other); |
--- |
4402 |
bool unionAssumed(std::optional Other); |
--- |
| 4403 |
|
--- |
4403 |
|
--- |
| 4404 |
/// Helper to track validity and fixpoint |
--- |
4404 |
/// Helper to track validity and fixpoint |
--- |
| 4405 |
BooleanState BS; |
--- |
4405 |
BooleanState BS; |
--- |
| 4406 |
|
--- |
4406 |
|
--- |
| 4407 |
/// An assumed simplified value. Initially, it is set to std::nullopt, which |
--- |
4407 |
/// An assumed simplified value. Initially, it is set to std::nullopt, which |
--- |
| 4408 |
/// means that the value is not clear under current assumption. If in the |
--- |
4408 |
/// means that the value is not clear under current assumption. If in the |
--- |
| 4409 |
/// pessimistic state, getAssumedSimplifiedValue doesn't return this value but |
--- |
4409 |
/// pessimistic state, getAssumedSimplifiedValue doesn't return this value but |
--- |
| 4410 |
/// returns orignal associated value. |
--- |
4410 |
/// returns orignal associated value. |
--- |
| 4411 |
std::optional SimplifiedAssociatedValue; |
--- |
4411 |
std::optional SimplifiedAssociatedValue; |
--- |
| 4412 |
}; |
--- |
4412 |
}; |
--- |
| 4413 |
|
--- |
4413 |
|
--- |
| 4414 |
/// An abstract interface for value simplify abstract attribute. |
--- |
4414 |
/// An abstract interface for value simplify abstract attribute. |
--- |
| 4415 |
struct AAValueSimplify |
--- |
4415 |
struct AAValueSimplify |
--- |
| 4416 |
: public StateWrapper { |
--- |
4416 |
: public StateWrapper { |
--- |
| 4417 |
using Base = StateWrapper; |
--- |
4417 |
using Base = StateWrapper; |
--- |
| 4418 |
AAValueSimplify(const IRPosition &IRP, Attributor &A) |
--- |
4418 |
AAValueSimplify(const IRPosition &IRP, Attributor &A) |
--- |
| 4419 |
: Base(IRP, IRP.getAssociatedType()) {} |
--- |
4419 |
: Base(IRP, IRP.getAssociatedType()) {} |
--- |
| 4420 |
|
--- |
4420 |
|
--- |
| 4421 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4421 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4422 |
static AAValueSimplify &createForPosition(const IRPosition &IRP, |
--- |
4422 |
static AAValueSimplify &createForPosition(const IRPosition &IRP, |
--- |
| 4423 |
Attributor &A); |
--- |
4423 |
Attributor &A); |
--- |
| 4424 |
|
--- |
4424 |
|
--- |
| 4425 |
/// See AbstractAttribute::getName() |
--- |
4425 |
/// See AbstractAttribute::getName() |
--- |
| 4426 |
const std::string getName() const override { return "AAValueSimplify"; } |
--- |
4426 |
const std::string getName() const override { return "AAValueSimplify"; } |
--- |
| 4427 |
|
--- |
4427 |
|
--- |
| 4428 |
/// See AbstractAttribute::getIdAddr() |
--- |
4428 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4429 |
const char *getIdAddr() const override { return &ID; } |
--- |
4429 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4430 |
|
--- |
4430 |
|
--- |
| 4431 |
/// This function should return true if the type of the \p AA is |
--- |
4431 |
/// This function should return true if the type of the \p AA is |
--- |
| 4432 |
/// AAValueSimplify |
--- |
4432 |
/// AAValueSimplify |
--- |
| 4433 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4433 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4434 |
return (AA->getIdAddr() == &ID); |
--- |
4434 |
return (AA->getIdAddr() == &ID); |
--- |
| 4435 |
} |
--- |
4435 |
} |
--- |
| 4436 |
|
--- |
4436 |
|
--- |
| 4437 |
/// Unique ID (due to the unique address) |
--- |
4437 |
/// Unique ID (due to the unique address) |
--- |
| 4438 |
static const char ID; |
--- |
4438 |
static const char ID; |
--- |
| 4439 |
|
--- |
4439 |
|
--- |
| 4440 |
private: |
--- |
4440 |
private: |
--- |
| 4441 |
/// Return an assumed simplified value if a single candidate is found. If |
--- |
4441 |
/// Return an assumed simplified value if a single candidate is found. If |
--- |
| 4442 |
/// there cannot be one, return original value. If it is not clear yet, return |
--- |
4442 |
/// there cannot be one, return original value. If it is not clear yet, return |
--- |
| 4443 |
/// std::nullopt. |
--- |
4443 |
/// std::nullopt. |
--- |
| 4444 |
/// |
--- |
4444 |
/// |
--- |
| 4445 |
/// Use `Attributor::getAssumedSimplified` for value simplification. |
--- |
4445 |
/// Use `Attributor::getAssumedSimplified` for value simplification. |
--- |
| 4446 |
virtual std::optional |
--- |
4446 |
virtual std::optional |
--- |
| 4447 |
getAssumedSimplifiedValue(Attributor &A) const = 0; |
--- |
4447 |
getAssumedSimplifiedValue(Attributor &A) const = 0; |
--- |
| 4448 |
|
--- |
4448 |
|
--- |
| 4449 |
friend struct Attributor; |
--- |
4449 |
friend struct Attributor; |
--- |
| 4450 |
}; |
--- |
4450 |
}; |
--- |
| 4451 |
|
--- |
4451 |
|
--- |
| 4452 |
struct AAHeapToStack : public StateWrapper { |
--- |
4452 |
struct AAHeapToStack : public StateWrapper { |
--- |
| 4453 |
using Base = StateWrapper; |
--- |
4453 |
using Base = StateWrapper; |
--- |
| 4454 |
AAHeapToStack(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
4454 |
AAHeapToStack(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 4455 |
|
--- |
4455 |
|
--- |
| 4456 |
/// Returns true if HeapToStack conversion is assumed to be possible. |
--- |
4456 |
/// Returns true if HeapToStack conversion is assumed to be possible. |
--- |
| 4457 |
virtual bool isAssumedHeapToStack(const CallBase &CB) const = 0; |
--- |
4457 |
virtual bool isAssumedHeapToStack(const CallBase &CB) const = 0; |
--- |
| 4458 |
|
--- |
4458 |
|
--- |
| 4459 |
/// Returns true if HeapToStack conversion is assumed and the CB is a |
--- |
4459 |
/// Returns true if HeapToStack conversion is assumed and the CB is a |
--- |
| 4460 |
/// callsite to a free operation to be removed. |
--- |
4460 |
/// callsite to a free operation to be removed. |
--- |
| 4461 |
virtual bool isAssumedHeapToStackRemovedFree(CallBase &CB) const = 0; |
--- |
4461 |
virtual bool isAssumedHeapToStackRemovedFree(CallBase &CB) const = 0; |
--- |
| 4462 |
|
--- |
4462 |
|
--- |
| 4463 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4463 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4464 |
static AAHeapToStack &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
4464 |
static AAHeapToStack &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 4465 |
|
--- |
4465 |
|
--- |
| 4466 |
/// See AbstractAttribute::getName() |
--- |
4466 |
/// See AbstractAttribute::getName() |
--- |
| 4467 |
const std::string getName() const override { return "AAHeapToStack"; } |
--- |
4467 |
const std::string getName() const override { return "AAHeapToStack"; } |
--- |
| 4468 |
|
--- |
4468 |
|
--- |
| 4469 |
/// See AbstractAttribute::getIdAddr() |
--- |
4469 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4470 |
const char *getIdAddr() const override { return &ID; } |
--- |
4470 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4471 |
|
--- |
4471 |
|
--- |
| 4472 |
/// This function should return true if the type of the \p AA is AAHeapToStack |
--- |
4472 |
/// This function should return true if the type of the \p AA is AAHeapToStack |
--- |
| 4473 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4473 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4474 |
return (AA->getIdAddr() == &ID); |
--- |
4474 |
return (AA->getIdAddr() == &ID); |
--- |
| 4475 |
} |
--- |
4475 |
} |
--- |
| 4476 |
|
--- |
4476 |
|
--- |
| 4477 |
/// Unique ID (due to the unique address) |
--- |
4477 |
/// Unique ID (due to the unique address) |
--- |
| 4478 |
static const char ID; |
--- |
4478 |
static const char ID; |
--- |
| 4479 |
}; |
--- |
4479 |
}; |
--- |
| 4480 |
|
--- |
4480 |
|
--- |
| 4481 |
/// An abstract interface for privatizability. |
--- |
4481 |
/// An abstract interface for privatizability. |
--- |
| 4482 |
/// |
--- |
4482 |
/// |
--- |
| 4483 |
/// A pointer is privatizable if it can be replaced by a new, private one. |
--- |
4483 |
/// A pointer is privatizable if it can be replaced by a new, private one. |
--- |
| 4484 |
/// Privatizing pointer reduces the use count, interaction between unrelated |
--- |
4484 |
/// Privatizing pointer reduces the use count, interaction between unrelated |
--- |
| 4485 |
/// code parts. |
--- |
4485 |
/// code parts. |
--- |
| 4486 |
/// |
--- |
4486 |
/// |
--- |
| 4487 |
/// In order for a pointer to be privatizable its value cannot be observed |
--- |
4487 |
/// In order for a pointer to be privatizable its value cannot be observed |
--- |
| 4488 |
/// (=nocapture), it is (for now) not written (=readonly & noalias), we know |
--- |
4488 |
/// (=nocapture), it is (for now) not written (=readonly & noalias), we know |
--- |
| 4489 |
/// what values are necessary to make the private copy look like the original |
--- |
4489 |
/// what values are necessary to make the private copy look like the original |
--- |
| 4490 |
/// one, and the values we need can be loaded (=dereferenceable). |
--- |
4490 |
/// one, and the values we need can be loaded (=dereferenceable). |
--- |
| 4491 |
struct AAPrivatizablePtr |
--- |
4491 |
struct AAPrivatizablePtr |
--- |
| 4492 |
: public StateWrapper { |
--- |
4492 |
: public StateWrapper { |
--- |
| 4493 |
using Base = StateWrapper; |
--- |
4493 |
using Base = StateWrapper; |
--- |
| 4494 |
AAPrivatizablePtr(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
4494 |
AAPrivatizablePtr(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 4495 |
|
--- |
4495 |
|
--- |
| 4496 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4496 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4497 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
4497 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 4498 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
4498 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 4499 |
return false; |
0 |
4499 |
return false; |
0 |
| 4500 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
4500 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 4501 |
} |
--- |
4501 |
} |
--- |
| 4502 |
|
--- |
4502 |
|
--- |
| 4503 |
/// Returns true if pointer privatization is assumed to be possible. |
--- |
4503 |
/// Returns true if pointer privatization is assumed to be possible. |
--- |
| 4504 |
bool isAssumedPrivatizablePtr() const { return getAssumed(); } |
--- |
4504 |
bool isAssumedPrivatizablePtr() const { return getAssumed(); } |
--- |
| 4505 |
|
--- |
4505 |
|
--- |
| 4506 |
/// Returns true if pointer privatization is known to be possible. |
--- |
4506 |
/// Returns true if pointer privatization is known to be possible. |
--- |
| 4507 |
bool isKnownPrivatizablePtr() const { return getKnown(); } |
--- |
4507 |
bool isKnownPrivatizablePtr() const { return getKnown(); } |
--- |
| 4508 |
|
--- |
4508 |
|
--- |
| 4509 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
4509 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 4510 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
4510 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
| 4511 |
|
--- |
4511 |
|
--- |
| 4512 |
/// Return the type we can choose for a private copy of the underlying |
--- |
4512 |
/// Return the type we can choose for a private copy of the underlying |
--- |
| 4513 |
/// value. std::nullopt means it is not clear yet, nullptr means there is |
--- |
4513 |
/// value. std::nullopt means it is not clear yet, nullptr means there is |
--- |
| 4514 |
/// none. |
--- |
4514 |
/// none. |
--- |
| 4515 |
virtual std::optional getPrivatizableType() const = 0; |
--- |
4515 |
virtual std::optional getPrivatizableType() const = 0; |
--- |
| 4516 |
|
--- |
4516 |
|
--- |
| 4517 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4517 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4518 |
static AAPrivatizablePtr &createForPosition(const IRPosition &IRP, |
--- |
4518 |
static AAPrivatizablePtr &createForPosition(const IRPosition &IRP, |
--- |
| 4519 |
Attributor &A); |
--- |
4519 |
Attributor &A); |
--- |
| 4520 |
|
--- |
4520 |
|
--- |
| 4521 |
/// See AbstractAttribute::getName() |
--- |
4521 |
/// See AbstractAttribute::getName() |
--- |
| 4522 |
const std::string getName() const override { return "AAPrivatizablePtr"; } |
--- |
4522 |
const std::string getName() const override { return "AAPrivatizablePtr"; } |
--- |
| 4523 |
|
--- |
4523 |
|
--- |
| 4524 |
/// See AbstractAttribute::getIdAddr() |
--- |
4524 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4525 |
const char *getIdAddr() const override { return &ID; } |
--- |
4525 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4526 |
|
--- |
4526 |
|
--- |
| 4527 |
/// This function should return true if the type of the \p AA is |
--- |
4527 |
/// This function should return true if the type of the \p AA is |
--- |
| 4528 |
/// AAPricatizablePtr |
--- |
4528 |
/// AAPricatizablePtr |
--- |
| 4529 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4529 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4530 |
return (AA->getIdAddr() == &ID); |
--- |
4530 |
return (AA->getIdAddr() == &ID); |
--- |
| 4531 |
} |
--- |
4531 |
} |
--- |
| 4532 |
|
--- |
4532 |
|
--- |
| 4533 |
/// Unique ID (due to the unique address) |
--- |
4533 |
/// Unique ID (due to the unique address) |
--- |
| 4534 |
static const char ID; |
--- |
4534 |
static const char ID; |
--- |
| 4535 |
}; |
--- |
4535 |
}; |
--- |
| 4536 |
|
--- |
4536 |
|
--- |
| 4537 |
/// An abstract interface for memory access kind related attributes |
--- |
4537 |
/// An abstract interface for memory access kind related attributes |
--- |
| 4538 |
/// (readnone/readonly/writeonly). |
--- |
4538 |
/// (readnone/readonly/writeonly). |
--- |
| 4539 |
struct AAMemoryBehavior |
--- |
4539 |
struct AAMemoryBehavior |
--- |
| 4540 |
: public IRAttribute< |
--- |
4540 |
: public IRAttribute< |
--- |
| 4541 |
Attribute::ReadNone, |
--- |
4541 |
Attribute::ReadNone, |
--- |
| 4542 |
StateWrapper, AbstractAttribute>, |
--- |
4542 |
StateWrapper, AbstractAttribute>, |
--- |
| 4543 |
AAMemoryBehavior> { |
--- |
4543 |
AAMemoryBehavior> { |
--- |
| 4544 |
AAMemoryBehavior(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
4544 |
AAMemoryBehavior(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 4545 |
|
--- |
4545 |
|
--- |
| 4546 |
/// See AbstractAttribute::hasTrivialInitializer. |
--- |
4546 |
/// See AbstractAttribute::hasTrivialInitializer. |
--- |
| 4547 |
static bool hasTrivialInitializer() { return false; } |
0 |
4547 |
static bool hasTrivialInitializer() { return false; } |
0 |
| 4548 |
|
--- |
4548 |
|
--- |
| 4549 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4549 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4550 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
4550 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 4551 |
if (!IRP.isFunctionScope() && |
0 |
4551 |
if (!IRP.isFunctionScope() && |
0 |
| 4552 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
4552 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 4553 |
return false; |
0 |
4553 |
return false; |
0 |
| 4554 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
4554 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 4555 |
} |
--- |
4555 |
} |
--- |
| 4556 |
|
--- |
4556 |
|
--- |
| 4557 |
/// State encoding bits. A set bit in the state means the property holds. |
--- |
4557 |
/// State encoding bits. A set bit in the state means the property holds. |
--- |
| 4558 |
/// BEST_STATE is the best possible state, 0 the worst possible state. |
--- |
4558 |
/// BEST_STATE is the best possible state, 0 the worst possible state. |
--- |
| 4559 |
enum { |
--- |
4559 |
enum { |
--- |
| 4560 |
NO_READS = 1 << 0, |
--- |
4560 |
NO_READS = 1 << 0, |
--- |
| 4561 |
NO_WRITES = 1 << 1, |
--- |
4561 |
NO_WRITES = 1 << 1, |
--- |
| 4562 |
NO_ACCESSES = NO_READS | NO_WRITES, |
--- |
4562 |
NO_ACCESSES = NO_READS | NO_WRITES, |
--- |
| 4563 |
|
--- |
4563 |
|
--- |
| 4564 |
BEST_STATE = NO_ACCESSES, |
--- |
4564 |
BEST_STATE = NO_ACCESSES, |
--- |
| 4565 |
}; |
--- |
4565 |
}; |
--- |
| 4566 |
static_assert(BEST_STATE == getBestState(), "Unexpected BEST_STATE value"); |
--- |
4566 |
static_assert(BEST_STATE == getBestState(), "Unexpected BEST_STATE value"); |
--- |
| 4567 |
|
--- |
4567 |
|
--- |
| 4568 |
/// Return true if we know that the underlying value is not read or accessed |
--- |
4568 |
/// Return true if we know that the underlying value is not read or accessed |
--- |
| 4569 |
/// in its respective scope. |
--- |
4569 |
/// in its respective scope. |
--- |
| 4570 |
bool isKnownReadNone() const { return isKnown(NO_ACCESSES); } |
0 |
4570 |
bool isKnownReadNone() const { return isKnown(NO_ACCESSES); } |
0 |
| 4571 |
|
--- |
4571 |
|
--- |
| 4572 |
/// Return true if we assume that the underlying value is not read or accessed |
--- |
4572 |
/// Return true if we assume that the underlying value is not read or accessed |
--- |
| 4573 |
/// in its respective scope. |
--- |
4573 |
/// in its respective scope. |
--- |
| 4574 |
bool isAssumedReadNone() const { return isAssumed(NO_ACCESSES); } |
0 |
4574 |
bool isAssumedReadNone() const { return isAssumed(NO_ACCESSES); } |
0 |
| 4575 |
|
--- |
4575 |
|
--- |
| 4576 |
/// Return true if we know that the underlying value is not accessed |
--- |
4576 |
/// Return true if we know that the underlying value is not accessed |
--- |
| 4577 |
/// (=written) in its respective scope. |
--- |
4577 |
/// (=written) in its respective scope. |
--- |
| 4578 |
bool isKnownReadOnly() const { return isKnown(NO_WRITES); } |
0 |
4578 |
bool isKnownReadOnly() const { return isKnown(NO_WRITES); } |
0 |
| 4579 |
|
--- |
4579 |
|
--- |
| 4580 |
/// Return true if we assume that the underlying value is not accessed |
--- |
4580 |
/// Return true if we assume that the underlying value is not accessed |
--- |
| 4581 |
/// (=written) in its respective scope. |
--- |
4581 |
/// (=written) in its respective scope. |
--- |
| 4582 |
bool isAssumedReadOnly() const { return isAssumed(NO_WRITES); } |
0 |
4582 |
bool isAssumedReadOnly() const { return isAssumed(NO_WRITES); } |
0 |
| 4583 |
|
--- |
4583 |
|
--- |
| 4584 |
/// Return true if we know that the underlying value is not read in its |
--- |
4584 |
/// Return true if we know that the underlying value is not read in its |
--- |
| 4585 |
/// respective scope. |
--- |
4585 |
/// respective scope. |
--- |
| 4586 |
bool isKnownWriteOnly() const { return isKnown(NO_READS); } |
--- |
4586 |
bool isKnownWriteOnly() const { return isKnown(NO_READS); } |
--- |
| 4587 |
|
--- |
4587 |
|
--- |
| 4588 |
/// Return true if we assume that the underlying value is not read in its |
--- |
4588 |
/// Return true if we assume that the underlying value is not read in its |
--- |
| 4589 |
/// respective scope. |
--- |
4589 |
/// respective scope. |
--- |
| 4590 |
bool isAssumedWriteOnly() const { return isAssumed(NO_READS); } |
--- |
4590 |
bool isAssumedWriteOnly() const { return isAssumed(NO_READS); } |
--- |
| 4591 |
|
--- |
4591 |
|
--- |
| 4592 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4592 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4593 |
static AAMemoryBehavior &createForPosition(const IRPosition &IRP, |
--- |
4593 |
static AAMemoryBehavior &createForPosition(const IRPosition &IRP, |
--- |
| 4594 |
Attributor &A); |
--- |
4594 |
Attributor &A); |
--- |
| 4595 |
|
--- |
4595 |
|
--- |
| 4596 |
/// See AbstractAttribute::getName() |
--- |
4596 |
/// See AbstractAttribute::getName() |
--- |
| 4597 |
const std::string getName() const override { return "AAMemoryBehavior"; } |
--- |
4597 |
const std::string getName() const override { return "AAMemoryBehavior"; } |
--- |
| 4598 |
|
--- |
4598 |
|
--- |
| 4599 |
/// See AbstractAttribute::getIdAddr() |
--- |
4599 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4600 |
const char *getIdAddr() const override { return &ID; } |
--- |
4600 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4601 |
|
--- |
4601 |
|
--- |
| 4602 |
/// This function should return true if the type of the \p AA is |
--- |
4602 |
/// This function should return true if the type of the \p AA is |
--- |
| 4603 |
/// AAMemoryBehavior |
--- |
4603 |
/// AAMemoryBehavior |
--- |
| 4604 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4604 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4605 |
return (AA->getIdAddr() == &ID); |
--- |
4605 |
return (AA->getIdAddr() == &ID); |
--- |
| 4606 |
} |
--- |
4606 |
} |
--- |
| 4607 |
|
--- |
4607 |
|
--- |
| 4608 |
/// Unique ID (due to the unique address) |
--- |
4608 |
/// Unique ID (due to the unique address) |
--- |
| 4609 |
static const char ID; |
--- |
4609 |
static const char ID; |
--- |
| 4610 |
}; |
--- |
4610 |
}; |
--- |
| 4611 |
|
--- |
4611 |
|
--- |
| 4612 |
/// An abstract interface for all memory location attributes |
--- |
4612 |
/// An abstract interface for all memory location attributes |
--- |
| 4613 |
/// (readnone/argmemonly/inaccessiblememonly/inaccessibleorargmemonly). |
--- |
4613 |
/// (readnone/argmemonly/inaccessiblememonly/inaccessibleorargmemonly). |
--- |
| 4614 |
struct AAMemoryLocation |
--- |
4614 |
struct AAMemoryLocation |
--- |
| 4615 |
: public IRAttribute< |
--- |
4615 |
: public IRAttribute< |
--- |
| 4616 |
Attribute::ReadNone, |
--- |
4616 |
Attribute::ReadNone, |
--- |
| 4617 |
StateWrapper, AbstractAttribute>, |
--- |
4617 |
StateWrapper, AbstractAttribute>, |
--- |
| 4618 |
AAMemoryLocation> { |
--- |
4618 |
AAMemoryLocation> { |
--- |
| 4619 |
using MemoryLocationsKind = StateType::base_t; |
--- |
4619 |
using MemoryLocationsKind = StateType::base_t; |
--- |
| 4620 |
|
--- |
4620 |
|
--- |
| 4621 |
AAMemoryLocation(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
4621 |
AAMemoryLocation(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 4622 |
|
--- |
4622 |
|
--- |
| 4623 |
/// See AbstractAttribute::hasTrivialInitializer. |
--- |
4623 |
/// See AbstractAttribute::hasTrivialInitializer. |
--- |
| 4624 |
static bool hasTrivialInitializer() { return false; } |
0 |
4624 |
static bool hasTrivialInitializer() { return false; } |
0 |
| 4625 |
|
--- |
4625 |
|
--- |
| 4626 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4626 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4627 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
4627 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 4628 |
if (!IRP.isFunctionScope() && |
0 |
4628 |
if (!IRP.isFunctionScope() && |
0 |
| 4629 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
4629 |
!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 4630 |
return false; |
0 |
4630 |
return false; |
0 |
| 4631 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
4631 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 4632 |
} |
--- |
4632 |
} |
--- |
| 4633 |
|
--- |
4633 |
|
--- |
| 4634 |
/// Encoding of different locations that could be accessed by a memory |
--- |
4634 |
/// Encoding of different locations that could be accessed by a memory |
--- |
| 4635 |
/// access. |
--- |
4635 |
/// access. |
--- |
| 4636 |
enum { |
--- |
4636 |
enum { |
--- |
| 4637 |
ALL_LOCATIONS = 0, |
--- |
4637 |
ALL_LOCATIONS = 0, |
--- |
| 4638 |
NO_LOCAL_MEM = 1 << 0, |
--- |
4638 |
NO_LOCAL_MEM = 1 << 0, |
--- |
| 4639 |
NO_CONST_MEM = 1 << 1, |
--- |
4639 |
NO_CONST_MEM = 1 << 1, |
--- |
| 4640 |
NO_GLOBAL_INTERNAL_MEM = 1 << 2, |
--- |
4640 |
NO_GLOBAL_INTERNAL_MEM = 1 << 2, |
--- |
| 4641 |
NO_GLOBAL_EXTERNAL_MEM = 1 << 3, |
--- |
4641 |
NO_GLOBAL_EXTERNAL_MEM = 1 << 3, |
--- |
| 4642 |
NO_GLOBAL_MEM = NO_GLOBAL_INTERNAL_MEM | NO_GLOBAL_EXTERNAL_MEM, |
--- |
4642 |
NO_GLOBAL_MEM = NO_GLOBAL_INTERNAL_MEM | NO_GLOBAL_EXTERNAL_MEM, |
--- |
| 4643 |
NO_ARGUMENT_MEM = 1 << 4, |
--- |
4643 |
NO_ARGUMENT_MEM = 1 << 4, |
--- |
| 4644 |
NO_INACCESSIBLE_MEM = 1 << 5, |
--- |
4644 |
NO_INACCESSIBLE_MEM = 1 << 5, |
--- |
| 4645 |
NO_MALLOCED_MEM = 1 << 6, |
--- |
4645 |
NO_MALLOCED_MEM = 1 << 6, |
--- |
| 4646 |
NO_UNKOWN_MEM = 1 << 7, |
--- |
4646 |
NO_UNKOWN_MEM = 1 << 7, |
--- |
| 4647 |
NO_LOCATIONS = NO_LOCAL_MEM | NO_CONST_MEM | NO_GLOBAL_INTERNAL_MEM | |
--- |
4647 |
NO_LOCATIONS = NO_LOCAL_MEM | NO_CONST_MEM | NO_GLOBAL_INTERNAL_MEM | |
--- |
| 4648 |
NO_GLOBAL_EXTERNAL_MEM | NO_ARGUMENT_MEM | |
--- |
4648 |
NO_GLOBAL_EXTERNAL_MEM | NO_ARGUMENT_MEM | |
--- |
| 4649 |
NO_INACCESSIBLE_MEM | NO_MALLOCED_MEM | NO_UNKOWN_MEM, |
--- |
4649 |
NO_INACCESSIBLE_MEM | NO_MALLOCED_MEM | NO_UNKOWN_MEM, |
--- |
| 4650 |
|
--- |
4650 |
|
--- |
| 4651 |
// Helper bit to track if we gave up or not. |
--- |
4651 |
// Helper bit to track if we gave up or not. |
--- |
| 4652 |
VALID_STATE = NO_LOCATIONS + 1, |
--- |
4652 |
VALID_STATE = NO_LOCATIONS + 1, |
--- |
| 4653 |
|
--- |
4653 |
|
--- |
| 4654 |
BEST_STATE = NO_LOCATIONS | VALID_STATE, |
--- |
4654 |
BEST_STATE = NO_LOCATIONS | VALID_STATE, |
--- |
| 4655 |
}; |
--- |
4655 |
}; |
--- |
| 4656 |
static_assert(BEST_STATE == getBestState(), "Unexpected BEST_STATE value"); |
--- |
4656 |
static_assert(BEST_STATE == getBestState(), "Unexpected BEST_STATE value"); |
--- |
| 4657 |
|
--- |
4657 |
|
--- |
| 4658 |
/// Return true if we know that the associated functions has no observable |
--- |
4658 |
/// Return true if we know that the associated functions has no observable |
--- |
| 4659 |
/// accesses. |
--- |
4659 |
/// accesses. |
--- |
| 4660 |
bool isKnownReadNone() const { return isKnown(NO_LOCATIONS); } |
0 |
4660 |
bool isKnownReadNone() const { return isKnown(NO_LOCATIONS); } |
0 |
| 4661 |
|
--- |
4661 |
|
--- |
| 4662 |
/// Return true if we assume that the associated functions has no observable |
--- |
4662 |
/// Return true if we assume that the associated functions has no observable |
--- |
| 4663 |
/// accesses. |
--- |
4663 |
/// accesses. |
--- |
| 4664 |
bool isAssumedReadNone() const { |
0 |
4664 |
bool isAssumedReadNone() const { |
0 |
| 4665 |
return isAssumed(NO_LOCATIONS) || isAssumedStackOnly(); |
0 |
4665 |
return isAssumed(NO_LOCATIONS) || isAssumedStackOnly(); |
0 |
| 4666 |
} |
--- |
4666 |
} |
--- |
| 4667 |
|
--- |
4667 |
|
--- |
| 4668 |
/// Return true if we know that the associated functions has at most |
--- |
4668 |
/// Return true if we know that the associated functions has at most |
--- |
| 4669 |
/// local/stack accesses. |
--- |
4669 |
/// local/stack accesses. |
--- |
| 4670 |
bool isKnowStackOnly() const { |
--- |
4670 |
bool isKnowStackOnly() const { |
--- |
| 4671 |
return isKnown(inverseLocation(NO_LOCAL_MEM, true, true)); |
--- |
4671 |
return isKnown(inverseLocation(NO_LOCAL_MEM, true, true)); |
--- |
| 4672 |
} |
--- |
4672 |
} |
--- |
| 4673 |
|
--- |
4673 |
|
--- |
| 4674 |
/// Return true if we assume that the associated functions has at most |
--- |
4674 |
/// Return true if we assume that the associated functions has at most |
--- |
| 4675 |
/// local/stack accesses. |
--- |
4675 |
/// local/stack accesses. |
--- |
| 4676 |
bool isAssumedStackOnly() const { |
0 |
4676 |
bool isAssumedStackOnly() const { |
0 |
| 4677 |
return isAssumed(inverseLocation(NO_LOCAL_MEM, true, true)); |
0 |
4677 |
return isAssumed(inverseLocation(NO_LOCAL_MEM, true, true)); |
0 |
| 4678 |
} |
--- |
4678 |
} |
--- |
| 4679 |
|
--- |
4679 |
|
--- |
| 4680 |
/// Return true if we know that the underlying value will only access |
--- |
4680 |
/// Return true if we know that the underlying value will only access |
--- |
| 4681 |
/// inaccesible memory only (see Attribute::InaccessibleMemOnly). |
--- |
4681 |
/// inaccesible memory only (see Attribute::InaccessibleMemOnly). |
--- |
| 4682 |
bool isKnownInaccessibleMemOnly() const { |
--- |
4682 |
bool isKnownInaccessibleMemOnly() const { |
--- |
| 4683 |
return isKnown(inverseLocation(NO_INACCESSIBLE_MEM, true, true)); |
--- |
4683 |
return isKnown(inverseLocation(NO_INACCESSIBLE_MEM, true, true)); |
--- |
| 4684 |
} |
--- |
4684 |
} |
--- |
| 4685 |
|
--- |
4685 |
|
--- |
| 4686 |
/// Return true if we assume that the underlying value will only access |
--- |
4686 |
/// Return true if we assume that the underlying value will only access |
--- |
| 4687 |
/// inaccesible memory only (see Attribute::InaccessibleMemOnly). |
--- |
4687 |
/// inaccesible memory only (see Attribute::InaccessibleMemOnly). |
--- |
| 4688 |
bool isAssumedInaccessibleMemOnly() const { |
--- |
4688 |
bool isAssumedInaccessibleMemOnly() const { |
--- |
| 4689 |
return isAssumed(inverseLocation(NO_INACCESSIBLE_MEM, true, true)); |
--- |
4689 |
return isAssumed(inverseLocation(NO_INACCESSIBLE_MEM, true, true)); |
--- |
| 4690 |
} |
--- |
4690 |
} |
--- |
| 4691 |
|
--- |
4691 |
|
--- |
| 4692 |
/// Return true if we know that the underlying value will only access |
--- |
4692 |
/// Return true if we know that the underlying value will only access |
--- |
| 4693 |
/// argument pointees (see Attribute::ArgMemOnly). |
--- |
4693 |
/// argument pointees (see Attribute::ArgMemOnly). |
--- |
| 4694 |
bool isKnownArgMemOnly() const { |
--- |
4694 |
bool isKnownArgMemOnly() const { |
--- |
| 4695 |
return isKnown(inverseLocation(NO_ARGUMENT_MEM, true, true)); |
--- |
4695 |
return isKnown(inverseLocation(NO_ARGUMENT_MEM, true, true)); |
--- |
| 4696 |
} |
--- |
4696 |
} |
--- |
| 4697 |
|
--- |
4697 |
|
--- |
| 4698 |
/// Return true if we assume that the underlying value will only access |
--- |
4698 |
/// Return true if we assume that the underlying value will only access |
--- |
| 4699 |
/// argument pointees (see Attribute::ArgMemOnly). |
--- |
4699 |
/// argument pointees (see Attribute::ArgMemOnly). |
--- |
| 4700 |
bool isAssumedArgMemOnly() const { |
--- |
4700 |
bool isAssumedArgMemOnly() const { |
--- |
| 4701 |
return isAssumed(inverseLocation(NO_ARGUMENT_MEM, true, true)); |
--- |
4701 |
return isAssumed(inverseLocation(NO_ARGUMENT_MEM, true, true)); |
--- |
| 4702 |
} |
--- |
4702 |
} |
--- |
| 4703 |
|
--- |
4703 |
|
--- |
| 4704 |
/// Return true if we know that the underlying value will only access |
--- |
4704 |
/// Return true if we know that the underlying value will only access |
--- |
| 4705 |
/// inaccesible memory or argument pointees (see |
--- |
4705 |
/// inaccesible memory or argument pointees (see |
--- |
| 4706 |
/// Attribute::InaccessibleOrArgMemOnly). |
--- |
4706 |
/// Attribute::InaccessibleOrArgMemOnly). |
--- |
| 4707 |
bool isKnownInaccessibleOrArgMemOnly() const { |
--- |
4707 |
bool isKnownInaccessibleOrArgMemOnly() const { |
--- |
| 4708 |
return isKnown( |
--- |
4708 |
return isKnown( |
--- |
| 4709 |
inverseLocation(NO_INACCESSIBLE_MEM | NO_ARGUMENT_MEM, true, true)); |
--- |
4709 |
inverseLocation(NO_INACCESSIBLE_MEM | NO_ARGUMENT_MEM, true, true)); |
--- |
| 4710 |
} |
--- |
4710 |
} |
--- |
| 4711 |
|
--- |
4711 |
|
--- |
| 4712 |
/// Return true if we assume that the underlying value will only access |
--- |
4712 |
/// Return true if we assume that the underlying value will only access |
--- |
| 4713 |
/// inaccesible memory or argument pointees (see |
--- |
4713 |
/// inaccesible memory or argument pointees (see |
--- |
| 4714 |
/// Attribute::InaccessibleOrArgMemOnly). |
--- |
4714 |
/// Attribute::InaccessibleOrArgMemOnly). |
--- |
| 4715 |
bool isAssumedInaccessibleOrArgMemOnly() const { |
--- |
4715 |
bool isAssumedInaccessibleOrArgMemOnly() const { |
--- |
| 4716 |
return isAssumed( |
--- |
4716 |
return isAssumed( |
--- |
| 4717 |
inverseLocation(NO_INACCESSIBLE_MEM | NO_ARGUMENT_MEM, true, true)); |
--- |
4717 |
inverseLocation(NO_INACCESSIBLE_MEM | NO_ARGUMENT_MEM, true, true)); |
--- |
| 4718 |
} |
--- |
4718 |
} |
--- |
| 4719 |
|
--- |
4719 |
|
--- |
| 4720 |
/// Return true if the underlying value may access memory through arguement |
--- |
4720 |
/// Return true if the underlying value may access memory through arguement |
--- |
| 4721 |
/// pointers of the associated function, if any. |
--- |
4721 |
/// pointers of the associated function, if any. |
--- |
| 4722 |
bool mayAccessArgMem() const { return !isAssumed(NO_ARGUMENT_MEM); } |
--- |
4722 |
bool mayAccessArgMem() const { return !isAssumed(NO_ARGUMENT_MEM); } |
--- |
| 4723 |
|
--- |
4723 |
|
--- |
| 4724 |
/// Return true if only the memory locations specififed by \p MLK are assumed |
--- |
4724 |
/// Return true if only the memory locations specififed by \p MLK are assumed |
--- |
| 4725 |
/// to be accessed by the associated function. |
--- |
4725 |
/// to be accessed by the associated function. |
--- |
| 4726 |
bool isAssumedSpecifiedMemOnly(MemoryLocationsKind MLK) const { |
--- |
4726 |
bool isAssumedSpecifiedMemOnly(MemoryLocationsKind MLK) const { |
--- |
| 4727 |
return isAssumed(MLK); |
--- |
4727 |
return isAssumed(MLK); |
--- |
| 4728 |
} |
--- |
4728 |
} |
--- |
| 4729 |
|
--- |
4729 |
|
--- |
| 4730 |
/// Return the locations that are assumed to be not accessed by the associated |
--- |
4730 |
/// Return the locations that are assumed to be not accessed by the associated |
--- |
| 4731 |
/// function, if any. |
--- |
4731 |
/// function, if any. |
--- |
| 4732 |
MemoryLocationsKind getAssumedNotAccessedLocation() const { |
--- |
4732 |
MemoryLocationsKind getAssumedNotAccessedLocation() const { |
--- |
| 4733 |
return getAssumed(); |
--- |
4733 |
return getAssumed(); |
--- |
| 4734 |
} |
--- |
4734 |
} |
--- |
| 4735 |
|
--- |
4735 |
|
--- |
| 4736 |
/// Return the inverse of location \p Loc, thus for NO_XXX the return |
--- |
4736 |
/// Return the inverse of location \p Loc, thus for NO_XXX the return |
--- |
| 4737 |
/// describes ONLY_XXX. The flags \p AndLocalMem and \p AndConstMem determine |
--- |
4737 |
/// describes ONLY_XXX. The flags \p AndLocalMem and \p AndConstMem determine |
--- |
| 4738 |
/// if local (=stack) and constant memory are allowed as well. Most of the |
--- |
4738 |
/// if local (=stack) and constant memory are allowed as well. Most of the |
--- |
| 4739 |
/// time we do want them to be included, e.g., argmemonly allows accesses via |
--- |
4739 |
/// time we do want them to be included, e.g., argmemonly allows accesses via |
--- |
| 4740 |
/// argument pointers or local or constant memory accesses. |
--- |
4740 |
/// argument pointers or local or constant memory accesses. |
--- |
| 4741 |
static MemoryLocationsKind |
--- |
4741 |
static MemoryLocationsKind |
--- |
| 4742 |
inverseLocation(MemoryLocationsKind Loc, bool AndLocalMem, bool AndConstMem) { |
0 |
4742 |
inverseLocation(MemoryLocationsKind Loc, bool AndLocalMem, bool AndConstMem) { |
0 |
| 4743 |
return NO_LOCATIONS & ~(Loc | (AndLocalMem ? NO_LOCAL_MEM : 0) | |
0 |
4743 |
return NO_LOCATIONS & ~(Loc | (AndLocalMem ? NO_LOCAL_MEM : 0) | |
0 |
| 4744 |
(AndConstMem ? NO_CONST_MEM : 0)); |
0 |
4744 |
(AndConstMem ? NO_CONST_MEM : 0)); |
0 |
| 4745 |
}; |
--- |
4745 |
}; |
--- |
| 4746 |
|
--- |
4746 |
|
--- |
| 4747 |
/// Return the locations encoded by \p MLK as a readable string. |
--- |
4747 |
/// Return the locations encoded by \p MLK as a readable string. |
--- |
| 4748 |
static std::string getMemoryLocationsAsStr(MemoryLocationsKind MLK); |
--- |
4748 |
static std::string getMemoryLocationsAsStr(MemoryLocationsKind MLK); |
--- |
| 4749 |
|
--- |
4749 |
|
--- |
| 4750 |
/// Simple enum to distinguish read/write/read-write accesses. |
--- |
4750 |
/// Simple enum to distinguish read/write/read-write accesses. |
--- |
| 4751 |
enum AccessKind { |
--- |
4751 |
enum AccessKind { |
--- |
| 4752 |
NONE = 0, |
--- |
4752 |
NONE = 0, |
--- |
| 4753 |
READ = 1 << 0, |
--- |
4753 |
READ = 1 << 0, |
--- |
| 4754 |
WRITE = 1 << 1, |
--- |
4754 |
WRITE = 1 << 1, |
--- |
| 4755 |
READ_WRITE = READ | WRITE, |
--- |
4755 |
READ_WRITE = READ | WRITE, |
--- |
| 4756 |
}; |
--- |
4756 |
}; |
--- |
| 4757 |
|
--- |
4757 |
|
--- |
| 4758 |
/// Check \p Pred on all accesses to the memory kinds specified by \p MLK. |
--- |
4758 |
/// Check \p Pred on all accesses to the memory kinds specified by \p MLK. |
--- |
| 4759 |
/// |
--- |
4759 |
/// |
--- |
| 4760 |
/// This method will evaluate \p Pred on all accesses (access instruction + |
--- |
4760 |
/// This method will evaluate \p Pred on all accesses (access instruction + |
--- |
| 4761 |
/// underlying accessed memory pointer) and it will return true if \p Pred |
--- |
4761 |
/// underlying accessed memory pointer) and it will return true if \p Pred |
--- |
| 4762 |
/// holds every time. |
--- |
4762 |
/// holds every time. |
--- |
| 4763 |
virtual bool checkForAllAccessesToMemoryKind( |
--- |
4763 |
virtual bool checkForAllAccessesToMemoryKind( |
--- |
| 4764 |
function_ref
| --- |
4764 |
function_ref
| --- |
| |
| 4765 |
MemoryLocationsKind)> |
--- |
4765 |
MemoryLocationsKind)> |
--- |
| 4766 |
Pred, |
--- |
4766 |
Pred, |
--- |
| 4767 |
MemoryLocationsKind MLK) const = 0; |
--- |
4767 |
MemoryLocationsKind MLK) const = 0; |
--- |
| 4768 |
|
--- |
4768 |
|
--- |
| 4769 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4769 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4770 |
static AAMemoryLocation &createForPosition(const IRPosition &IRP, |
--- |
4770 |
static AAMemoryLocation &createForPosition(const IRPosition &IRP, |
--- |
| 4771 |
Attributor &A); |
--- |
4771 |
Attributor &A); |
--- |
| 4772 |
|
--- |
4772 |
|
--- |
| 4773 |
/// See AbstractState::getAsStr(Attributor). |
--- |
4773 |
/// See AbstractState::getAsStr(Attributor). |
--- |
| 4774 |
const std::string getAsStr(Attributor *A) const override { |
--- |
4774 |
const std::string getAsStr(Attributor *A) const override { |
--- |
| 4775 |
return getMemoryLocationsAsStr(getAssumedNotAccessedLocation()); |
--- |
4775 |
return getMemoryLocationsAsStr(getAssumedNotAccessedLocation()); |
--- |
| 4776 |
} |
--- |
4776 |
} |
--- |
| 4777 |
|
--- |
4777 |
|
--- |
| 4778 |
/// See AbstractAttribute::getName() |
--- |
4778 |
/// See AbstractAttribute::getName() |
--- |
| 4779 |
const std::string getName() const override { return "AAMemoryLocation"; } |
--- |
4779 |
const std::string getName() const override { return "AAMemoryLocation"; } |
--- |
| 4780 |
|
--- |
4780 |
|
--- |
| 4781 |
/// See AbstractAttribute::getIdAddr() |
--- |
4781 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4782 |
const char *getIdAddr() const override { return &ID; } |
--- |
4782 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4783 |
|
--- |
4783 |
|
--- |
| 4784 |
/// This function should return true if the type of the \p AA is |
--- |
4784 |
/// This function should return true if the type of the \p AA is |
--- |
| 4785 |
/// AAMemoryLocation |
--- |
4785 |
/// AAMemoryLocation |
--- |
| 4786 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4786 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4787 |
return (AA->getIdAddr() == &ID); |
--- |
4787 |
return (AA->getIdAddr() == &ID); |
--- |
| 4788 |
} |
--- |
4788 |
} |
--- |
| 4789 |
|
--- |
4789 |
|
--- |
| 4790 |
/// Unique ID (due to the unique address) |
--- |
4790 |
/// Unique ID (due to the unique address) |
--- |
| 4791 |
static const char ID; |
--- |
4791 |
static const char ID; |
--- |
| 4792 |
}; |
--- |
4792 |
}; |
--- |
| 4793 |
|
--- |
4793 |
|
--- |
| 4794 |
/// An abstract interface for range value analysis. |
--- |
4794 |
/// An abstract interface for range value analysis. |
--- |
| 4795 |
struct AAValueConstantRange |
--- |
4795 |
struct AAValueConstantRange |
--- |
| 4796 |
: public StateWrapper { |
--- |
4796 |
: public StateWrapper { |
--- |
| 4797 |
using Base = StateWrapper; |
--- |
4797 |
using Base = StateWrapper; |
--- |
| 4798 |
AAValueConstantRange(const IRPosition &IRP, Attributor &A) |
--- |
4798 |
AAValueConstantRange(const IRPosition &IRP, Attributor &A) |
--- |
| 4799 |
: Base(IRP, IRP.getAssociatedType()->getIntegerBitWidth()) {} |
--- |
4799 |
: Base(IRP, IRP.getAssociatedType()->getIntegerBitWidth()) {} |
--- |
| 4800 |
|
--- |
4800 |
|
--- |
| 4801 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
4801 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 4802 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
--- |
4802 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
--- |
| 4803 |
if (!IRP.getAssociatedType()->isIntegerTy()) |
--- |
4803 |
if (!IRP.getAssociatedType()->isIntegerTy()) |
--- |
| 4804 |
return false; |
--- |
4804 |
return false; |
--- |
| 4805 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
--- |
4805 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
--- |
| 4806 |
} |
--- |
4806 |
} |
--- |
| 4807 |
|
--- |
4807 |
|
--- |
| 4808 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
4808 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 4809 |
static bool requiresCallersForArgOrFunction() { return true; } |
--- |
4809 |
static bool requiresCallersForArgOrFunction() { return true; } |
--- |
| 4810 |
|
--- |
4810 |
|
--- |
| 4811 |
/// See AbstractAttribute::getState(...). |
--- |
4811 |
/// See AbstractAttribute::getState(...). |
--- |
| 4812 |
IntegerRangeState &getState() override { return *this; } |
--- |
4812 |
IntegerRangeState &getState() override { return *this; } |
--- |
| 4813 |
const IntegerRangeState &getState() const override { return *this; } |
--- |
4813 |
const IntegerRangeState &getState() const override { return *this; } |
--- |
| 4814 |
|
--- |
4814 |
|
--- |
| 4815 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
4815 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 4816 |
static AAValueConstantRange &createForPosition(const IRPosition &IRP, |
--- |
4816 |
static AAValueConstantRange &createForPosition(const IRPosition &IRP, |
--- |
| 4817 |
Attributor &A); |
--- |
4817 |
Attributor &A); |
--- |
| 4818 |
|
--- |
4818 |
|
--- |
| 4819 |
/// Return an assumed range for the associated value a program point \p CtxI. |
--- |
4819 |
/// Return an assumed range for the associated value a program point \p CtxI. |
--- |
| 4820 |
/// If \p I is nullptr, simply return an assumed range. |
--- |
4820 |
/// If \p I is nullptr, simply return an assumed range. |
--- |
| 4821 |
virtual ConstantRange |
--- |
4821 |
virtual ConstantRange |
--- |
| 4822 |
getAssumedConstantRange(Attributor &A, |
--- |
4822 |
getAssumedConstantRange(Attributor &A, |
--- |
| 4823 |
const Instruction *CtxI = nullptr) const = 0; |
--- |
4823 |
const Instruction *CtxI = nullptr) const = 0; |
--- |
| 4824 |
|
--- |
4824 |
|
--- |
| 4825 |
/// Return a known range for the associated value at a program point \p CtxI. |
--- |
4825 |
/// Return a known range for the associated value at a program point \p CtxI. |
--- |
| 4826 |
/// If \p I is nullptr, simply return a known range. |
--- |
4826 |
/// If \p I is nullptr, simply return a known range. |
--- |
| 4827 |
virtual ConstantRange |
--- |
4827 |
virtual ConstantRange |
--- |
| 4828 |
getKnownConstantRange(Attributor &A, |
--- |
4828 |
getKnownConstantRange(Attributor &A, |
--- |
| 4829 |
const Instruction *CtxI = nullptr) const = 0; |
--- |
4829 |
const Instruction *CtxI = nullptr) const = 0; |
--- |
| 4830 |
|
--- |
4830 |
|
--- |
| 4831 |
/// Return an assumed constant for the associated value a program point \p |
--- |
4831 |
/// Return an assumed constant for the associated value a program point \p |
--- |
| 4832 |
/// CtxI. |
--- |
4832 |
/// CtxI. |
--- |
| 4833 |
std::optional |
--- |
4833 |
std::optional |
--- |
| 4834 |
getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const { |
--- |
4834 |
getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const { |
--- |
| 4835 |
ConstantRange RangeV = getAssumedConstantRange(A, CtxI); |
--- |
4835 |
ConstantRange RangeV = getAssumedConstantRange(A, CtxI); |
--- |
| 4836 |
if (auto *C = RangeV.getSingleElement()) { |
--- |
4836 |
if (auto *C = RangeV.getSingleElement()) { |
--- |
| 4837 |
Type *Ty = getAssociatedValue().getType(); |
--- |
4837 |
Type *Ty = getAssociatedValue().getType(); |
--- |
| 4838 |
return cast_or_null( |
--- |
4838 |
return cast_or_null( |
--- |
| 4839 |
AA::getWithType(*ConstantInt::get(Ty->getContext(), *C), *Ty)); |
--- |
4839 |
AA::getWithType(*ConstantInt::get(Ty->getContext(), *C), *Ty)); |
--- |
| 4840 |
} |
--- |
4840 |
} |
--- |
| 4841 |
if (RangeV.isEmptySet()) |
--- |
4841 |
if (RangeV.isEmptySet()) |
--- |
| 4842 |
return std::nullopt; |
--- |
4842 |
return std::nullopt; |
--- |
| 4843 |
return nullptr; |
--- |
4843 |
return nullptr; |
--- |
| 4844 |
} |
--- |
4844 |
} |
--- |
| 4845 |
|
--- |
4845 |
|
--- |
| 4846 |
/// See AbstractAttribute::getName() |
--- |
4846 |
/// See AbstractAttribute::getName() |
--- |
| 4847 |
const std::string getName() const override { return "AAValueConstantRange"; } |
--- |
4847 |
const std::string getName() const override { return "AAValueConstantRange"; } |
--- |
| 4848 |
|
--- |
4848 |
|
--- |
| 4849 |
/// See AbstractAttribute::getIdAddr() |
--- |
4849 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 4850 |
const char *getIdAddr() const override { return &ID; } |
--- |
4850 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 4851 |
|
--- |
4851 |
|
--- |
| 4852 |
/// This function should return true if the type of the \p AA is |
--- |
4852 |
/// This function should return true if the type of the \p AA is |
--- |
| 4853 |
/// AAValueConstantRange |
--- |
4853 |
/// AAValueConstantRange |
--- |
| 4854 |
static bool classof(const AbstractAttribute *AA) { |
--- |
4854 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 4855 |
return (AA->getIdAddr() == &ID); |
--- |
4855 |
return (AA->getIdAddr() == &ID); |
--- |
| 4856 |
} |
--- |
4856 |
} |
--- |
| 4857 |
|
--- |
4857 |
|
--- |
| 4858 |
/// Unique ID (due to the unique address) |
--- |
4858 |
/// Unique ID (due to the unique address) |
--- |
| 4859 |
static const char ID; |
--- |
4859 |
static const char ID; |
--- |
| 4860 |
}; |
--- |
4860 |
}; |
--- |
| 4861 |
|
--- |
4861 |
|
--- |
| 4862 |
/// A class for a set state. |
--- |
4862 |
/// A class for a set state. |
--- |
| 4863 |
/// The assumed boolean state indicates whether the corresponding set is full |
--- |
4863 |
/// The assumed boolean state indicates whether the corresponding set is full |
--- |
| 4864 |
/// set or not. If the assumed state is false, this is the worst state. The |
--- |
4864 |
/// set or not. If the assumed state is false, this is the worst state. The |
--- |
| 4865 |
/// worst state (invalid state) of set of potential values is when the set |
--- |
4865 |
/// worst state (invalid state) of set of potential values is when the set |
--- |
| 4866 |
/// contains every possible value (i.e. we cannot in any way limit the value |
--- |
4866 |
/// contains every possible value (i.e. we cannot in any way limit the value |
--- |
| 4867 |
/// that the target position can take). That never happens naturally, we only |
--- |
4867 |
/// that the target position can take). That never happens naturally, we only |
--- |
| 4868 |
/// force it. As for the conditions under which we force it, see |
--- |
4868 |
/// force it. As for the conditions under which we force it, see |
--- |
| 4869 |
/// AAPotentialConstantValues. |
--- |
4869 |
/// AAPotentialConstantValues. |
--- |
| 4870 |
template struct PotentialValuesState : AbstractState { |
--- |
4870 |
template struct PotentialValuesState : AbstractState { |
--- |
| 4871 |
using SetTy = SmallSetVector; |
--- |
4871 |
using SetTy = SmallSetVector; |
--- |
| 4872 |
|
--- |
4872 |
|
--- |
| 4873 |
PotentialValuesState() : IsValidState(true), UndefIsContained(false) {} |
--- |
4873 |
PotentialValuesState() : IsValidState(true), UndefIsContained(false) {} |
--- |
| 4874 |
|
--- |
4874 |
|
--- |
| 4875 |
PotentialValuesState(bool IsValid) |
--- |
4875 |
PotentialValuesState(bool IsValid) |
--- |
| 4876 |
: IsValidState(IsValid), UndefIsContained(false) {} |
--- |
4876 |
: IsValidState(IsValid), UndefIsContained(false) {} |
--- |
| 4877 |
|
--- |
4877 |
|
--- |
| 4878 |
/// See AbstractState::isValidState(...) |
--- |
4878 |
/// See AbstractState::isValidState(...) |
--- |
| 4879 |
bool isValidState() const override { return IsValidState.isValidState(); } |
--- |
4879 |
bool isValidState() const override { return IsValidState.isValidState(); } |
--- |
| 4880 |
|
--- |
4880 |
|
--- |
| 4881 |
/// See AbstractState::isAtFixpoint(...) |
--- |
4881 |
/// See AbstractState::isAtFixpoint(...) |
--- |
| 4882 |
bool isAtFixpoint() const override { return IsValidState.isAtFixpoint(); } |
--- |
4882 |
bool isAtFixpoint() const override { return IsValidState.isAtFixpoint(); } |
--- |
| 4883 |
|
--- |
4883 |
|
--- |
| 4884 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
4884 |
/// See AbstractState::indicatePessimisticFixpoint(...) |
--- |
| 4885 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
4885 |
ChangeStatus indicatePessimisticFixpoint() override { |
--- |
| 4886 |
return IsValidState.indicatePessimisticFixpoint(); |
--- |
4886 |
return IsValidState.indicatePessimisticFixpoint(); |
--- |
| 4887 |
} |
--- |
4887 |
} |
--- |
| 4888 |
|
--- |
4888 |
|
--- |
| 4889 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
4889 |
/// See AbstractState::indicateOptimisticFixpoint(...) |
--- |
| 4890 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
4890 |
ChangeStatus indicateOptimisticFixpoint() override { |
--- |
| 4891 |
return IsValidState.indicateOptimisticFixpoint(); |
--- |
4891 |
return IsValidState.indicateOptimisticFixpoint(); |
--- |
| 4892 |
} |
--- |
4892 |
} |
--- |
| 4893 |
|
--- |
4893 |
|
--- |
| 4894 |
/// Return the assumed state |
--- |
4894 |
/// Return the assumed state |
--- |
| 4895 |
PotentialValuesState &getAssumed() { return *this; } |
--- |
4895 |
PotentialValuesState &getAssumed() { return *this; } |
--- |
| 4896 |
const PotentialValuesState &getAssumed() const { return *this; } |
--- |
4896 |
const PotentialValuesState &getAssumed() const { return *this; } |
--- |
| 4897 |
|
--- |
4897 |
|
--- |
| 4898 |
/// Return this set. We should check whether this set is valid or not by |
--- |
4898 |
/// Return this set. We should check whether this set is valid or not by |
--- |
| 4899 |
/// isValidState() before calling this function. |
--- |
4899 |
/// isValidState() before calling this function. |
--- |
| 4900 |
const SetTy &getAssumedSet() const { |
0 |
4900 |
const SetTy &getAssumedSet() const { |
0 |
| 4901 |
assert(isValidState() && "This set shoud not be used when it is invalid!"); |
0 |
4901 |
assert(isValidState() && "This set shoud not be used when it is invalid!"); |
0 |
| 4902 |
return Set; |
0 |
4902 |
return Set; |
0 |
| 4903 |
} |
--- |
4903 |
} |
--- |
| 4904 |
|
--- |
4904 |
|
--- |
| 4905 |
/// Returns whether this state contains an undef value or not. |
--- |
4905 |
/// Returns whether this state contains an undef value or not. |
--- |
| 4906 |
bool undefIsContained() const { |
0 |
4906 |
bool undefIsContained() const { |
0 |
| 4907 |
assert(isValidState() && "This flag shoud not be used when it is invalid!"); |
0 |
4907 |
assert(isValidState() && "This flag shoud not be used when it is invalid!"); |
0 |
| 4908 |
return UndefIsContained; |
0 |
4908 |
return UndefIsContained; |
0 |
| 4909 |
} |
--- |
4909 |
} |
--- |
| 4910 |
|
--- |
4910 |
|
--- |
| 4911 |
bool operator==(const PotentialValuesState &RHS) const { |
--- |
4911 |
bool operator==(const PotentialValuesState &RHS) const { |
--- |
| 4912 |
if (isValidState() != RHS.isValidState()) |
--- |
4912 |
if (isValidState() != RHS.isValidState()) |
--- |
| 4913 |
return false; |
--- |
4913 |
return false; |
--- |
| 4914 |
if (!isValidState() && !RHS.isValidState()) |
--- |
4914 |
if (!isValidState() && !RHS.isValidState()) |
--- |
| 4915 |
return true; |
--- |
4915 |
return true; |
--- |
| 4916 |
if (undefIsContained() != RHS.undefIsContained()) |
--- |
4916 |
if (undefIsContained() != RHS.undefIsContained()) |
--- |
| 4917 |
return false; |
--- |
4917 |
return false; |
--- |
| 4918 |
return Set == RHS.getAssumedSet(); |
--- |
4918 |
return Set == RHS.getAssumedSet(); |
--- |
| 4919 |
} |
--- |
4919 |
} |
--- |
| 4920 |
|
--- |
4920 |
|
--- |
| 4921 |
/// Maximum number of potential values to be tracked. |
--- |
4921 |
/// Maximum number of potential values to be tracked. |
--- |
| 4922 |
/// This is set by -attributor-max-potential-values command line option |
--- |
4922 |
/// This is set by -attributor-max-potential-values command line option |
--- |
| 4923 |
static unsigned MaxPotentialValues; |
--- |
4923 |
static unsigned MaxPotentialValues; |
--- |
| 4924 |
|
--- |
4924 |
|
--- |
| 4925 |
/// Return empty set as the best state of potential values. |
--- |
4925 |
/// Return empty set as the best state of potential values. |
--- |
| 4926 |
static PotentialValuesState getBestState() { |
--- |
4926 |
static PotentialValuesState getBestState() { |
--- |
| 4927 |
return PotentialValuesState(true); |
--- |
4927 |
return PotentialValuesState(true); |
--- |
| 4928 |
} |
--- |
4928 |
} |
--- |
| 4929 |
|
--- |
4929 |
|
--- |
| 4930 |
static PotentialValuesState getBestState(const PotentialValuesState &PVS) { |
--- |
4930 |
static PotentialValuesState getBestState(const PotentialValuesState &PVS) { |
--- |
| 4931 |
return getBestState(); |
--- |
4931 |
return getBestState(); |
--- |
| 4932 |
} |
--- |
4932 |
} |
--- |
| 4933 |
|
--- |
4933 |
|
--- |
| 4934 |
/// Return full set as the worst state of potential values. |
--- |
4934 |
/// Return full set as the worst state of potential values. |
--- |
| 4935 |
static PotentialValuesState getWorstState() { |
--- |
4935 |
static PotentialValuesState getWorstState() { |
--- |
| 4936 |
return PotentialValuesState(false); |
--- |
4936 |
return PotentialValuesState(false); |
--- |
| 4937 |
} |
--- |
4937 |
} |
--- |
| 4938 |
|
--- |
4938 |
|
--- |
| 4939 |
/// Union assumed set with the passed value. |
--- |
4939 |
/// Union assumed set with the passed value. |
--- |
| 4940 |
void unionAssumed(const MemberTy &C) { insert(C); } |
--- |
4940 |
void unionAssumed(const MemberTy &C) { insert(C); } |
--- |
| 4941 |
|
--- |
4941 |
|
--- |
| 4942 |
/// Union assumed set with assumed set of the passed state \p PVS. |
--- |
4942 |
/// Union assumed set with assumed set of the passed state \p PVS. |
--- |
| 4943 |
void unionAssumed(const PotentialValuesState &PVS) { unionWith(PVS); } |
--- |
4943 |
void unionAssumed(const PotentialValuesState &PVS) { unionWith(PVS); } |
--- |
| 4944 |
|
--- |
4944 |
|
--- |
| 4945 |
/// Union assumed set with an undef value. |
--- |
4945 |
/// Union assumed set with an undef value. |
--- |
| 4946 |
void unionAssumedWithUndef() { unionWithUndef(); } |
--- |
4946 |
void unionAssumedWithUndef() { unionWithUndef(); } |
--- |
| 4947 |
|
--- |
4947 |
|
--- |
| 4948 |
/// "Clamp" this state with \p PVS. |
--- |
4948 |
/// "Clamp" this state with \p PVS. |
--- |
| 4949 |
PotentialValuesState operator^=(const PotentialValuesState &PVS) { |
--- |
4949 |
PotentialValuesState operator^=(const PotentialValuesState &PVS) { |
--- |
| 4950 |
IsValidState ^= PVS.IsValidState; |
--- |
4950 |
IsValidState ^= PVS.IsValidState; |
--- |
| 4951 |
unionAssumed(PVS); |
--- |
4951 |
unionAssumed(PVS); |
--- |
| 4952 |
return *this; |
--- |
4952 |
return *this; |
--- |
| 4953 |
} |
--- |
4953 |
} |
--- |
| 4954 |
|
--- |
4954 |
|
--- |
| 4955 |
PotentialValuesState operator&=(const PotentialValuesState &PVS) { |
--- |
4955 |
PotentialValuesState operator&=(const PotentialValuesState &PVS) { |
--- |
| 4956 |
IsValidState &= PVS.IsValidState; |
--- |
4956 |
IsValidState &= PVS.IsValidState; |
--- |
| 4957 |
unionAssumed(PVS); |
--- |
4957 |
unionAssumed(PVS); |
--- |
| 4958 |
return *this; |
--- |
4958 |
return *this; |
--- |
| 4959 |
} |
--- |
4959 |
} |
--- |
| 4960 |
|
--- |
4960 |
|
--- |
| 4961 |
bool contains(const MemberTy &V) const { |
--- |
4961 |
bool contains(const MemberTy &V) const { |
--- |
| 4962 |
return !isValidState() ? true : Set.contains(V); |
--- |
4962 |
return !isValidState() ? true : Set.contains(V); |
--- |
| 4963 |
} |
--- |
4963 |
} |
--- |
| 4964 |
|
--- |
4964 |
|
--- |
| 4965 |
protected: |
--- |
4965 |
protected: |
--- |
| 4966 |
SetTy &getAssumedSet() { |
--- |
4966 |
SetTy &getAssumedSet() { |
--- |
| 4967 |
assert(isValidState() && "This set shoud not be used when it is invalid!"); |
--- |
4967 |
assert(isValidState() && "This set shoud not be used when it is invalid!"); |
--- |
| 4968 |
return Set; |
--- |
4968 |
return Set; |
--- |
| 4969 |
} |
--- |
4969 |
} |
--- |
| 4970 |
|
--- |
4970 |
|
--- |
| 4971 |
private: |
--- |
4971 |
private: |
--- |
| 4972 |
/// Check the size of this set, and invalidate when the size is no |
--- |
4972 |
/// Check the size of this set, and invalidate when the size is no |
--- |
| 4973 |
/// less than \p MaxPotentialValues threshold. |
--- |
4973 |
/// less than \p MaxPotentialValues threshold. |
--- |
| 4974 |
void checkAndInvalidate() { |
--- |
4974 |
void checkAndInvalidate() { |
--- |
| 4975 |
if (Set.size() >= MaxPotentialValues) |
--- |
4975 |
if (Set.size() >= MaxPotentialValues) |
--- |
| 4976 |
indicatePessimisticFixpoint(); |
--- |
4976 |
indicatePessimisticFixpoint(); |
--- |
| 4977 |
else |
--- |
4977 |
else |
--- |
| 4978 |
reduceUndefValue(); |
--- |
4978 |
reduceUndefValue(); |
--- |
| 4979 |
} |
--- |
4979 |
} |
--- |
| 4980 |
|
--- |
4980 |
|
--- |
| 4981 |
/// If this state contains both undef and not undef, we can reduce |
--- |
4981 |
/// If this state contains both undef and not undef, we can reduce |
--- |
| 4982 |
/// undef to the not undef value. |
--- |
4982 |
/// undef to the not undef value. |
--- |
| 4983 |
void reduceUndefValue() { UndefIsContained = UndefIsContained & Set.empty(); } |
--- |
4983 |
void reduceUndefValue() { UndefIsContained = UndefIsContained & Set.empty(); } |
--- |
| 4984 |
|
--- |
4984 |
|
--- |
| 4985 |
/// Insert an element into this set. |
--- |
4985 |
/// Insert an element into this set. |
--- |
| 4986 |
void insert(const MemberTy &C) { |
--- |
4986 |
void insert(const MemberTy &C) { |
--- |
| 4987 |
if (!isValidState()) |
--- |
4987 |
if (!isValidState()) |
--- |
| 4988 |
return; |
--- |
4988 |
return; |
--- |
| 4989 |
Set.insert(C); |
--- |
4989 |
Set.insert(C); |
--- |
| 4990 |
checkAndInvalidate(); |
--- |
4990 |
checkAndInvalidate(); |
--- |
| 4991 |
} |
--- |
4991 |
} |
--- |
| 4992 |
|
--- |
4992 |
|
--- |
| 4993 |
/// Take union with R. |
--- |
4993 |
/// Take union with R. |
--- |
| 4994 |
void unionWith(const PotentialValuesState &R) { |
--- |
4994 |
void unionWith(const PotentialValuesState &R) { |
--- |
| 4995 |
/// If this is a full set, do nothing. |
--- |
4995 |
/// If this is a full set, do nothing. |
--- |
| 4996 |
if (!isValidState()) |
--- |
4996 |
if (!isValidState()) |
--- |
| 4997 |
return; |
--- |
4997 |
return; |
--- |
| 4998 |
/// If R is full set, change L to a full set. |
--- |
4998 |
/// If R is full set, change L to a full set. |
--- |
| 4999 |
if (!R.isValidState()) { |
--- |
4999 |
if (!R.isValidState()) { |
--- |
| 5000 |
indicatePessimisticFixpoint(); |
--- |
5000 |
indicatePessimisticFixpoint(); |
--- |
| 5001 |
return; |
--- |
5001 |
return; |
--- |
| 5002 |
} |
--- |
5002 |
} |
--- |
| 5003 |
for (const MemberTy &C : R.Set) |
--- |
5003 |
for (const MemberTy &C : R.Set) |
--- |
| 5004 |
Set.insert(C); |
--- |
5004 |
Set.insert(C); |
--- |
| 5005 |
UndefIsContained |= R.undefIsContained(); |
--- |
5005 |
UndefIsContained |= R.undefIsContained(); |
--- |
| 5006 |
checkAndInvalidate(); |
--- |
5006 |
checkAndInvalidate(); |
--- |
| 5007 |
} |
--- |
5007 |
} |
--- |
| 5008 |
|
--- |
5008 |
|
--- |
| 5009 |
/// Take union with an undef value. |
--- |
5009 |
/// Take union with an undef value. |
--- |
| 5010 |
void unionWithUndef() { |
--- |
5010 |
void unionWithUndef() { |
--- |
| 5011 |
UndefIsContained = true; |
--- |
5011 |
UndefIsContained = true; |
--- |
| 5012 |
reduceUndefValue(); |
--- |
5012 |
reduceUndefValue(); |
--- |
| 5013 |
} |
--- |
5013 |
} |
--- |
| 5014 |
|
--- |
5014 |
|
--- |
| 5015 |
/// Take intersection with R. |
--- |
5015 |
/// Take intersection with R. |
--- |
| 5016 |
void intersectWith(const PotentialValuesState &R) { |
--- |
5016 |
void intersectWith(const PotentialValuesState &R) { |
--- |
| 5017 |
/// If R is a full set, do nothing. |
--- |
5017 |
/// If R is a full set, do nothing. |
--- |
| 5018 |
if (!R.isValidState()) |
--- |
5018 |
if (!R.isValidState()) |
--- |
| 5019 |
return; |
--- |
5019 |
return; |
--- |
| 5020 |
/// If this is a full set, change this to R. |
--- |
5020 |
/// If this is a full set, change this to R. |
--- |
| 5021 |
if (!isValidState()) { |
--- |
5021 |
if (!isValidState()) { |
--- |
| 5022 |
*this = R; |
--- |
5022 |
*this = R; |
--- |
| 5023 |
return; |
--- |
5023 |
return; |
--- |
| 5024 |
} |
--- |
5024 |
} |
--- |
| 5025 |
SetTy IntersectSet; |
--- |
5025 |
SetTy IntersectSet; |
--- |
| 5026 |
for (const MemberTy &C : Set) { |
--- |
5026 |
for (const MemberTy &C : Set) { |
--- |
| 5027 |
if (R.Set.count(C)) |
--- |
5027 |
if (R.Set.count(C)) |
--- |
| 5028 |
IntersectSet.insert(C); |
--- |
5028 |
IntersectSet.insert(C); |
--- |
| 5029 |
} |
--- |
5029 |
} |
--- |
| 5030 |
Set = IntersectSet; |
--- |
5030 |
Set = IntersectSet; |
--- |
| 5031 |
UndefIsContained &= R.undefIsContained(); |
--- |
5031 |
UndefIsContained &= R.undefIsContained(); |
--- |
| 5032 |
reduceUndefValue(); |
--- |
5032 |
reduceUndefValue(); |
--- |
| 5033 |
} |
--- |
5033 |
} |
--- |
| 5034 |
|
--- |
5034 |
|
--- |
| 5035 |
/// A helper state which indicate whether this state is valid or not. |
--- |
5035 |
/// A helper state which indicate whether this state is valid or not. |
--- |
| 5036 |
BooleanState IsValidState; |
--- |
5036 |
BooleanState IsValidState; |
--- |
| 5037 |
|
--- |
5037 |
|
--- |
| 5038 |
/// Container for potential values |
--- |
5038 |
/// Container for potential values |
--- |
| 5039 |
SetTy Set; |
--- |
5039 |
SetTy Set; |
--- |
| 5040 |
|
--- |
5040 |
|
--- |
| 5041 |
/// Flag for undef value |
--- |
5041 |
/// Flag for undef value |
--- |
| 5042 |
bool UndefIsContained; |
--- |
5042 |
bool UndefIsContained; |
--- |
| 5043 |
}; |
--- |
5043 |
}; |
--- |
| 5044 |
|
--- |
5044 |
|
--- |
| 5045 |
using PotentialConstantIntValuesState = PotentialValuesState; |
--- |
5045 |
using PotentialConstantIntValuesState = PotentialValuesState; |
--- |
| 5046 |
using PotentialLLVMValuesState = |
--- |
5046 |
using PotentialLLVMValuesState = |
--- |
| 5047 |
PotentialValuesState>; |
--- |
5047 |
PotentialValuesState>; |
--- |
| 5048 |
|
--- |
5048 |
|
--- |
| 5049 |
raw_ostream &operator<<(raw_ostream &OS, |
--- |
5049 |
raw_ostream &operator<<(raw_ostream &OS, |
--- |
| 5050 |
const PotentialConstantIntValuesState &R); |
--- |
5050 |
const PotentialConstantIntValuesState &R); |
--- |
| 5051 |
raw_ostream &operator<<(raw_ostream &OS, const PotentialLLVMValuesState &R); |
--- |
5051 |
raw_ostream &operator<<(raw_ostream &OS, const PotentialLLVMValuesState &R); |
--- |
| 5052 |
|
--- |
5052 |
|
--- |
| 5053 |
/// An abstract interface for potential values analysis. |
--- |
5053 |
/// An abstract interface for potential values analysis. |
--- |
| 5054 |
/// |
--- |
5054 |
/// |
--- |
| 5055 |
/// This AA collects potential values for each IR position. |
--- |
5055 |
/// This AA collects potential values for each IR position. |
--- |
| 5056 |
/// An assumed set of potential values is initialized with the empty set (the |
--- |
5056 |
/// An assumed set of potential values is initialized with the empty set (the |
--- |
| 5057 |
/// best state) and it will grow monotonically as we find more potential values |
--- |
5057 |
/// best state) and it will grow monotonically as we find more potential values |
--- |
| 5058 |
/// for this position. |
--- |
5058 |
/// for this position. |
--- |
| 5059 |
/// The set might be forced to the worst state, that is, to contain every |
--- |
5059 |
/// The set might be forced to the worst state, that is, to contain every |
--- |
| 5060 |
/// possible value for this position in 2 cases. |
--- |
5060 |
/// possible value for this position in 2 cases. |
--- |
| 5061 |
/// 1. We surpassed the \p MaxPotentialValues threshold. This includes the |
--- |
5061 |
/// 1. We surpassed the \p MaxPotentialValues threshold. This includes the |
--- |
| 5062 |
/// case that this position is affected (e.g. because of an operation) by a |
--- |
5062 |
/// case that this position is affected (e.g. because of an operation) by a |
--- |
| 5063 |
/// Value that is in the worst state. |
--- |
5063 |
/// Value that is in the worst state. |
--- |
| 5064 |
/// 2. We tried to initialize on a Value that we cannot handle (e.g. an |
--- |
5064 |
/// 2. We tried to initialize on a Value that we cannot handle (e.g. an |
--- |
| 5065 |
/// operator we do not currently handle). |
--- |
5065 |
/// operator we do not currently handle). |
--- |
| 5066 |
/// |
--- |
5066 |
/// |
--- |
| 5067 |
/// For non constant integers see AAPotentialValues. |
--- |
5067 |
/// For non constant integers see AAPotentialValues. |
--- |
| 5068 |
struct AAPotentialConstantValues |
--- |
5068 |
struct AAPotentialConstantValues |
--- |
| 5069 |
: public StateWrapper { |
--- |
5069 |
: public StateWrapper { |
--- |
| 5070 |
using Base = StateWrapper; |
--- |
5070 |
using Base = StateWrapper; |
--- |
| 5071 |
AAPotentialConstantValues(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
5071 |
AAPotentialConstantValues(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 5072 |
|
--- |
5072 |
|
--- |
| 5073 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
5073 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 5074 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
--- |
5074 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
--- |
| 5075 |
if (!IRP.getAssociatedType()->isIntegerTy()) |
--- |
5075 |
if (!IRP.getAssociatedType()->isIntegerTy()) |
--- |
| 5076 |
return false; |
--- |
5076 |
return false; |
--- |
| 5077 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
--- |
5077 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
--- |
| 5078 |
} |
--- |
5078 |
} |
--- |
| 5079 |
|
--- |
5079 |
|
--- |
| 5080 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
5080 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 5081 |
static bool requiresCallersForArgOrFunction() { return true; } |
--- |
5081 |
static bool requiresCallersForArgOrFunction() { return true; } |
--- |
| 5082 |
|
--- |
5082 |
|
--- |
| 5083 |
/// See AbstractAttribute::getState(...). |
--- |
5083 |
/// See AbstractAttribute::getState(...). |
--- |
| 5084 |
PotentialConstantIntValuesState &getState() override { return *this; } |
--- |
5084 |
PotentialConstantIntValuesState &getState() override { return *this; } |
--- |
| 5085 |
const PotentialConstantIntValuesState &getState() const override { |
--- |
5085 |
const PotentialConstantIntValuesState &getState() const override { |
--- |
| 5086 |
return *this; |
--- |
5086 |
return *this; |
--- |
| 5087 |
} |
--- |
5087 |
} |
--- |
| 5088 |
|
--- |
5088 |
|
--- |
| 5089 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5089 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5090 |
static AAPotentialConstantValues &createForPosition(const IRPosition &IRP, |
--- |
5090 |
static AAPotentialConstantValues &createForPosition(const IRPosition &IRP, |
--- |
| 5091 |
Attributor &A); |
--- |
5091 |
Attributor &A); |
--- |
| 5092 |
|
--- |
5092 |
|
--- |
| 5093 |
/// Return assumed constant for the associated value |
--- |
5093 |
/// Return assumed constant for the associated value |
--- |
| 5094 |
std::optional |
--- |
5094 |
std::optional |
--- |
| 5095 |
getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const { |
--- |
5095 |
getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const { |
--- |
| 5096 |
if (!isValidState()) |
--- |
5096 |
if (!isValidState()) |
--- |
| 5097 |
return nullptr; |
--- |
5097 |
return nullptr; |
--- |
| 5098 |
if (getAssumedSet().size() == 1) { |
--- |
5098 |
if (getAssumedSet().size() == 1) { |
--- |
| 5099 |
Type *Ty = getAssociatedValue().getType(); |
--- |
5099 |
Type *Ty = getAssociatedValue().getType(); |
--- |
| 5100 |
return cast_or_null(AA::getWithType( |
--- |
5100 |
return cast_or_null(AA::getWithType( |
--- |
| 5101 |
*ConstantInt::get(Ty->getContext(), *(getAssumedSet().begin())), |
--- |
5101 |
*ConstantInt::get(Ty->getContext(), *(getAssumedSet().begin())), |
--- |
| 5102 |
*Ty)); |
--- |
5102 |
*Ty)); |
--- |
| 5103 |
} |
--- |
5103 |
} |
--- |
| 5104 |
if (getAssumedSet().size() == 0) { |
--- |
5104 |
if (getAssumedSet().size() == 0) { |
--- |
| 5105 |
if (undefIsContained()) |
--- |
5105 |
if (undefIsContained()) |
--- |
| 5106 |
return UndefValue::get(getAssociatedValue().getType()); |
--- |
5106 |
return UndefValue::get(getAssociatedValue().getType()); |
--- |
| 5107 |
return std::nullopt; |
--- |
5107 |
return std::nullopt; |
--- |
| 5108 |
} |
--- |
5108 |
} |
--- |
| 5109 |
|
--- |
5109 |
|
--- |
| 5110 |
return nullptr; |
--- |
5110 |
return nullptr; |
--- |
| 5111 |
} |
--- |
5111 |
} |
--- |
| 5112 |
|
--- |
5112 |
|
--- |
| 5113 |
/// See AbstractAttribute::getName() |
--- |
5113 |
/// See AbstractAttribute::getName() |
--- |
| 5114 |
const std::string getName() const override { |
--- |
5114 |
const std::string getName() const override { |
--- |
| 5115 |
return "AAPotentialConstantValues"; |
--- |
5115 |
return "AAPotentialConstantValues"; |
--- |
| 5116 |
} |
--- |
5116 |
} |
--- |
| 5117 |
|
--- |
5117 |
|
--- |
| 5118 |
/// See AbstractAttribute::getIdAddr() |
--- |
5118 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5119 |
const char *getIdAddr() const override { return &ID; } |
--- |
5119 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5120 |
|
--- |
5120 |
|
--- |
| 5121 |
/// This function should return true if the type of the \p AA is |
--- |
5121 |
/// This function should return true if the type of the \p AA is |
--- |
| 5122 |
/// AAPotentialConstantValues |
--- |
5122 |
/// AAPotentialConstantValues |
--- |
| 5123 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5123 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5124 |
return (AA->getIdAddr() == &ID); |
--- |
5124 |
return (AA->getIdAddr() == &ID); |
--- |
| 5125 |
} |
--- |
5125 |
} |
--- |
| 5126 |
|
--- |
5126 |
|
--- |
| 5127 |
/// Unique ID (due to the unique address) |
--- |
5127 |
/// Unique ID (due to the unique address) |
--- |
| 5128 |
static const char ID; |
--- |
5128 |
static const char ID; |
--- |
| 5129 |
}; |
--- |
5129 |
}; |
--- |
| 5130 |
|
--- |
5130 |
|
--- |
| 5131 |
struct AAPotentialValues |
--- |
5131 |
struct AAPotentialValues |
--- |
| 5132 |
: public StateWrapper { |
--- |
5132 |
: public StateWrapper { |
--- |
| 5133 |
using Base = StateWrapper; |
--- |
5133 |
using Base = StateWrapper; |
--- |
| 5134 |
AAPotentialValues(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
5134 |
AAPotentialValues(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 5135 |
|
--- |
5135 |
|
--- |
| 5136 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
5136 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 5137 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
5137 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
| 5138 |
|
--- |
5138 |
|
--- |
| 5139 |
/// See AbstractAttribute::getState(...). |
--- |
5139 |
/// See AbstractAttribute::getState(...). |
--- |
| 5140 |
PotentialLLVMValuesState &getState() override { return *this; } |
--- |
5140 |
PotentialLLVMValuesState &getState() override { return *this; } |
--- |
| 5141 |
const PotentialLLVMValuesState &getState() const override { return *this; } |
--- |
5141 |
const PotentialLLVMValuesState &getState() const override { return *this; } |
--- |
| 5142 |
|
--- |
5142 |
|
--- |
| 5143 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5143 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5144 |
static AAPotentialValues &createForPosition(const IRPosition &IRP, |
--- |
5144 |
static AAPotentialValues &createForPosition(const IRPosition &IRP, |
--- |
| 5145 |
Attributor &A); |
--- |
5145 |
Attributor &A); |
--- |
| 5146 |
|
--- |
5146 |
|
--- |
| 5147 |
/// Extract the single value in \p Values if any. |
--- |
5147 |
/// Extract the single value in \p Values if any. |
--- |
| 5148 |
static Value *getSingleValue(Attributor &A, const AbstractAttribute &AA, |
--- |
5148 |
static Value *getSingleValue(Attributor &A, const AbstractAttribute &AA, |
--- |
| 5149 |
const IRPosition &IRP, |
--- |
5149 |
const IRPosition &IRP, |
--- |
| 5150 |
SmallVectorImpl &Values); |
--- |
5150 |
SmallVectorImpl &Values); |
--- |
| 5151 |
|
--- |
5151 |
|
--- |
| 5152 |
/// See AbstractAttribute::getName() |
--- |
5152 |
/// See AbstractAttribute::getName() |
--- |
| 5153 |
const std::string getName() const override { return "AAPotentialValues"; } |
--- |
5153 |
const std::string getName() const override { return "AAPotentialValues"; } |
--- |
| 5154 |
|
--- |
5154 |
|
--- |
| 5155 |
/// See AbstractAttribute::getIdAddr() |
--- |
5155 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5156 |
const char *getIdAddr() const override { return &ID; } |
--- |
5156 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5157 |
|
--- |
5157 |
|
--- |
| 5158 |
/// This function should return true if the type of the \p AA is |
--- |
5158 |
/// This function should return true if the type of the \p AA is |
--- |
| 5159 |
/// AAPotentialValues |
--- |
5159 |
/// AAPotentialValues |
--- |
| 5160 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5160 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5161 |
return (AA->getIdAddr() == &ID); |
--- |
5161 |
return (AA->getIdAddr() == &ID); |
--- |
| 5162 |
} |
--- |
5162 |
} |
--- |
| 5163 |
|
--- |
5163 |
|
--- |
| 5164 |
/// Unique ID (due to the unique address) |
--- |
5164 |
/// Unique ID (due to the unique address) |
--- |
| 5165 |
static const char ID; |
--- |
5165 |
static const char ID; |
--- |
| 5166 |
|
--- |
5166 |
|
--- |
| 5167 |
private: |
--- |
5167 |
private: |
--- |
| 5168 |
virtual bool getAssumedSimplifiedValues( |
--- |
5168 |
virtual bool getAssumedSimplifiedValues( |
--- |
| 5169 |
Attributor &A, SmallVectorImpl &Values, |
--- |
5169 |
Attributor &A, SmallVectorImpl &Values, |
--- |
| 5170 |
AA::ValueScope, bool RecurseForSelectAndPHI = false) const = 0; |
--- |
5170 |
AA::ValueScope, bool RecurseForSelectAndPHI = false) const = 0; |
--- |
| 5171 |
|
--- |
5171 |
|
--- |
| 5172 |
friend struct Attributor; |
--- |
5172 |
friend struct Attributor; |
--- |
| 5173 |
}; |
--- |
5173 |
}; |
--- |
| 5174 |
|
--- |
5174 |
|
--- |
| 5175 |
/// An abstract interface for all noundef attributes. |
--- |
5175 |
/// An abstract interface for all noundef attributes. |
--- |
| 5176 |
struct AANoUndef |
--- |
5176 |
struct AANoUndef |
--- |
| 5177 |
: public IRAttribute
| --- |
5177 |
: public IRAttribute
| --- |
| |
| 5178 |
StateWrapper, |
--- |
5178 |
StateWrapper, |
--- |
| 5179 |
AANoUndef> { |
--- |
5179 |
AANoUndef> { |
--- |
| 5180 |
AANoUndef(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
5180 |
AANoUndef(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 5181 |
|
--- |
5181 |
|
--- |
| 5182 |
/// See IRAttribute::isImpliedByUndef |
--- |
5182 |
/// See IRAttribute::isImpliedByUndef |
--- |
| 5183 |
static bool isImpliedByUndef() { return false; } |
--- |
5183 |
static bool isImpliedByUndef() { return false; } |
--- |
| 5184 |
|
--- |
5184 |
|
--- |
| 5185 |
/// See IRAttribute::isImpliedByPoison |
--- |
5185 |
/// See IRAttribute::isImpliedByPoison |
--- |
| 5186 |
static bool isImpliedByPoison() { return false; } |
--- |
5186 |
static bool isImpliedByPoison() { return false; } |
--- |
| 5187 |
|
--- |
5187 |
|
--- |
| 5188 |
/// See IRAttribute::isImpliedByIR |
--- |
5188 |
/// See IRAttribute::isImpliedByIR |
--- |
| 5189 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
5189 |
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, |
--- |
| 5190 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
5190 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 5191 |
bool IgnoreSubsumingPositions = false); |
--- |
5191 |
bool IgnoreSubsumingPositions = false); |
--- |
| 5192 |
|
--- |
5192 |
|
--- |
| 5193 |
/// Return true if we assume that the underlying value is noundef. |
--- |
5193 |
/// Return true if we assume that the underlying value is noundef. |
--- |
| 5194 |
bool isAssumedNoUndef() const { return getAssumed(); } |
--- |
5194 |
bool isAssumedNoUndef() const { return getAssumed(); } |
--- |
| 5195 |
|
--- |
5195 |
|
--- |
| 5196 |
/// Return true if we know that underlying value is noundef. |
--- |
5196 |
/// Return true if we know that underlying value is noundef. |
--- |
| 5197 |
bool isKnownNoUndef() const { return getKnown(); } |
--- |
5197 |
bool isKnownNoUndef() const { return getKnown(); } |
--- |
| 5198 |
|
--- |
5198 |
|
--- |
| 5199 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5199 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5200 |
static AANoUndef &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
5200 |
static AANoUndef &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 5201 |
|
--- |
5201 |
|
--- |
| 5202 |
/// See AbstractAttribute::getName() |
--- |
5202 |
/// See AbstractAttribute::getName() |
--- |
| 5203 |
const std::string getName() const override { return "AANoUndef"; } |
--- |
5203 |
const std::string getName() const override { return "AANoUndef"; } |
--- |
| 5204 |
|
--- |
5204 |
|
--- |
| 5205 |
/// See AbstractAttribute::getIdAddr() |
--- |
5205 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5206 |
const char *getIdAddr() const override { return &ID; } |
--- |
5206 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5207 |
|
--- |
5207 |
|
--- |
| 5208 |
/// This function should return true if the type of the \p AA is AANoUndef |
--- |
5208 |
/// This function should return true if the type of the \p AA is AANoUndef |
--- |
| 5209 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5209 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5210 |
return (AA->getIdAddr() == &ID); |
--- |
5210 |
return (AA->getIdAddr() == &ID); |
--- |
| 5211 |
} |
--- |
5211 |
} |
--- |
| 5212 |
|
--- |
5212 |
|
--- |
| 5213 |
/// Unique ID (due to the unique address) |
--- |
5213 |
/// Unique ID (due to the unique address) |
--- |
| 5214 |
static const char ID; |
--- |
5214 |
static const char ID; |
--- |
| 5215 |
}; |
--- |
5215 |
}; |
--- |
| 5216 |
|
--- |
5216 |
|
--- |
| 5217 |
struct AANoFPClass |
--- |
5217 |
struct AANoFPClass |
--- |
| 5218 |
: public IRAttribute< |
--- |
5218 |
: public IRAttribute< |
--- |
| 5219 |
Attribute::NoFPClass, |
--- |
5219 |
Attribute::NoFPClass, |
--- |
| 5220 |
StateWrapper, |
--- |
5220 |
StateWrapper, |
--- |
| 5221 |
AbstractAttribute>, |
--- |
5221 |
AbstractAttribute>, |
--- |
| 5222 |
AANoFPClass> { |
--- |
5222 |
AANoFPClass> { |
--- |
| 5223 |
using Base = StateWrapper, |
--- |
5223 |
using Base = StateWrapper, |
--- |
| 5224 |
AbstractAttribute>; |
--- |
5224 |
AbstractAttribute>; |
--- |
| 5225 |
|
--- |
5225 |
|
--- |
| 5226 |
AANoFPClass(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
5226 |
AANoFPClass(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {} |
--- |
| 5227 |
|
--- |
5227 |
|
--- |
| 5228 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
5228 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 5229 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
5229 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 5230 |
Type *Ty = IRP.getAssociatedType(); |
0 |
5230 |
Type *Ty = IRP.getAssociatedType(); |
0 |
| 5231 |
do { |
--- |
5231 |
do { |
--- |
| 5232 |
if (Ty->isFPOrFPVectorTy()) |
0 |
5232 |
if (Ty->isFPOrFPVectorTy()) |
0 |
| 5233 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
5233 |
return IRAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 5234 |
if (!Ty->isArrayTy()) |
0 |
5234 |
if (!Ty->isArrayTy()) |
0 |
| 5235 |
break; |
0 |
5235 |
break; |
0 |
| 5236 |
Ty = Ty->getArrayElementType(); |
0 |
5236 |
Ty = Ty->getArrayElementType(); |
0 |
| 5237 |
} while (true); |
--- |
5237 |
} while (true); |
--- |
| 5238 |
return false; |
0 |
5238 |
return false; |
0 |
| 5239 |
} |
--- |
5239 |
} |
--- |
| 5240 |
|
--- |
5240 |
|
--- |
| 5241 |
/// Return true if we assume that the underlying value is nofpclass. |
--- |
5241 |
/// Return true if we assume that the underlying value is nofpclass. |
--- |
| 5242 |
FPClassTest getAssumedNoFPClass() const { |
--- |
5242 |
FPClassTest getAssumedNoFPClass() const { |
--- |
| 5243 |
return static_cast(getAssumed()); |
--- |
5243 |
return static_cast(getAssumed()); |
--- |
| 5244 |
} |
--- |
5244 |
} |
--- |
| 5245 |
|
--- |
5245 |
|
--- |
| 5246 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5246 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5247 |
static AANoFPClass &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
5247 |
static AANoFPClass &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 5248 |
|
--- |
5248 |
|
--- |
| 5249 |
/// See AbstractAttribute::getName() |
--- |
5249 |
/// See AbstractAttribute::getName() |
--- |
| 5250 |
const std::string getName() const override { return "AANoFPClass"; } |
--- |
5250 |
const std::string getName() const override { return "AANoFPClass"; } |
--- |
| 5251 |
|
--- |
5251 |
|
--- |
| 5252 |
/// See AbstractAttribute::getIdAddr() |
--- |
5252 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5253 |
const char *getIdAddr() const override { return &ID; } |
--- |
5253 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5254 |
|
--- |
5254 |
|
--- |
| 5255 |
/// This function should return true if the type of the \p AA is AANoFPClass |
--- |
5255 |
/// This function should return true if the type of the \p AA is AANoFPClass |
--- |
| 5256 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5256 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5257 |
return (AA->getIdAddr() == &ID); |
--- |
5257 |
return (AA->getIdAddr() == &ID); |
--- |
| 5258 |
} |
--- |
5258 |
} |
--- |
| 5259 |
|
--- |
5259 |
|
--- |
| 5260 |
/// Unique ID (due to the unique address) |
--- |
5260 |
/// Unique ID (due to the unique address) |
--- |
| 5261 |
static const char ID; |
--- |
5261 |
static const char ID; |
--- |
| 5262 |
}; |
--- |
5262 |
}; |
--- |
| 5263 |
|
--- |
5263 |
|
--- |
| 5264 |
struct AACallGraphNode; |
--- |
5264 |
struct AACallGraphNode; |
--- |
| 5265 |
struct AACallEdges; |
--- |
5265 |
struct AACallEdges; |
--- |
| 5266 |
|
--- |
5266 |
|
--- |
| 5267 |
/// An Iterator for call edges, creates AACallEdges attributes in a lazy way. |
--- |
5267 |
/// An Iterator for call edges, creates AACallEdges attributes in a lazy way. |
--- |
| 5268 |
/// This iterator becomes invalid if the underlying edge list changes. |
--- |
5268 |
/// This iterator becomes invalid if the underlying edge list changes. |
--- |
| 5269 |
/// So This shouldn't outlive a iteration of Attributor. |
--- |
5269 |
/// So This shouldn't outlive a iteration of Attributor. |
--- |
| 5270 |
class AACallEdgeIterator |
--- |
5270 |
class AACallEdgeIterator |
--- |
| 5271 |
: public iterator_adaptor_base
| --- |
5271 |
: public iterator_adaptor_base
| --- |
| |
| 5272 |
SetVector::iterator> { |
--- |
5272 |
SetVector::iterator> { |
--- |
| 5273 |
AACallEdgeIterator(Attributor &A, SetVector::iterator Begin) |
0 |
5273 |
AACallEdgeIterator(Attributor &A, SetVector::iterator Begin) |
0 |
| 5274 |
: iterator_adaptor_base(Begin), A(A) {} |
0 |
5274 |
: iterator_adaptor_base(Begin), A(A) {} |
0 |
| 5275 |
|
--- |
5275 |
|
--- |
| 5276 |
public: |
--- |
5276 |
public: |
--- |
| 5277 |
AACallGraphNode *operator*() const; |
--- |
5277 |
AACallGraphNode *operator*() const; |
--- |
| 5278 |
|
--- |
5278 |
|
--- |
| 5279 |
private: |
--- |
5279 |
private: |
--- |
| 5280 |
Attributor &A; |
--- |
5280 |
Attributor &A; |
--- |
| 5281 |
friend AACallEdges; |
--- |
5281 |
friend AACallEdges; |
--- |
| 5282 |
friend AttributorCallGraph; |
--- |
5282 |
friend AttributorCallGraph; |
--- |
| 5283 |
}; |
--- |
5283 |
}; |
--- |
| 5284 |
|
--- |
5284 |
|
--- |
| 5285 |
struct AACallGraphNode { |
--- |
5285 |
struct AACallGraphNode { |
--- |
| 5286 |
AACallGraphNode(Attributor &A) : A(A) {} |
0 |
5286 |
AACallGraphNode(Attributor &A) : A(A) {} |
0 |
| 5287 |
virtual ~AACallGraphNode() = default; |
0 |
5287 |
virtual ~AACallGraphNode() = default; |
0 |
| 5288 |
|
--- |
5288 |
|
--- |
| 5289 |
virtual AACallEdgeIterator optimisticEdgesBegin() const = 0; |
--- |
5289 |
virtual AACallEdgeIterator optimisticEdgesBegin() const = 0; |
--- |
| 5290 |
virtual AACallEdgeIterator optimisticEdgesEnd() const = 0; |
--- |
5290 |
virtual AACallEdgeIterator optimisticEdgesEnd() const = 0; |
--- |
| 5291 |
|
--- |
5291 |
|
--- |
| 5292 |
/// Iterator range for exploring the call graph. |
--- |
5292 |
/// Iterator range for exploring the call graph. |
--- |
| 5293 |
iterator_range optimisticEdgesRange() const { |
0 |
5293 |
iterator_range optimisticEdgesRange() const { |
0 |
| 5294 |
return iterator_range(optimisticEdgesBegin(), |
0 |
5294 |
return iterator_range(optimisticEdgesBegin(), |
0 |
| 5295 |
optimisticEdgesEnd()); |
0 |
5295 |
optimisticEdgesEnd()); |
0 |
| 5296 |
} |
--- |
5296 |
} |
--- |
| 5297 |
|
--- |
5297 |
|
--- |
| 5298 |
protected: |
--- |
5298 |
protected: |
--- |
| 5299 |
/// Reference to Attributor needed for GraphTraits implementation. |
--- |
5299 |
/// Reference to Attributor needed for GraphTraits implementation. |
--- |
| 5300 |
Attributor &A; |
--- |
5300 |
Attributor &A; |
--- |
| 5301 |
}; |
--- |
5301 |
}; |
--- |
| 5302 |
|
--- |
5302 |
|
--- |
| 5303 |
/// An abstract state for querying live call edges. |
--- |
5303 |
/// An abstract state for querying live call edges. |
--- |
| 5304 |
/// This interface uses the Attributor's optimistic liveness |
--- |
5304 |
/// This interface uses the Attributor's optimistic liveness |
--- |
| 5305 |
/// information to compute the edges that are alive. |
--- |
5305 |
/// information to compute the edges that are alive. |
--- |
| 5306 |
struct AACallEdges : public StateWrapper, |
--- |
5306 |
struct AACallEdges : public StateWrapper, |
--- |
| 5307 |
AACallGraphNode { |
--- |
5307 |
AACallGraphNode { |
--- |
| 5308 |
using Base = StateWrapper; |
--- |
5308 |
using Base = StateWrapper; |
--- |
| 5309 |
|
--- |
5309 |
|
--- |
| 5310 |
AACallEdges(const IRPosition &IRP, Attributor &A) |
--- |
5310 |
AACallEdges(const IRPosition &IRP, Attributor &A) |
--- |
| 5311 |
: Base(IRP), AACallGraphNode(A) {} |
--- |
5311 |
: Base(IRP), AACallGraphNode(A) {} |
--- |
| 5312 |
|
--- |
5312 |
|
--- |
| 5313 |
/// The callee value is tracked beyond a simple stripPointerCasts, so we allow |
--- |
5313 |
/// The callee value is tracked beyond a simple stripPointerCasts, so we allow |
--- |
| 5314 |
/// unknown callees. |
--- |
5314 |
/// unknown callees. |
--- |
| 5315 |
static bool requiresCalleeForCallBase() { return false; } |
--- |
5315 |
static bool requiresCalleeForCallBase() { return false; } |
--- |
| 5316 |
|
--- |
5316 |
|
--- |
| 5317 |
/// Get the optimistic edges. |
--- |
5317 |
/// Get the optimistic edges. |
--- |
| 5318 |
virtual const SetVector &getOptimisticEdges() const = 0; |
--- |
5318 |
virtual const SetVector &getOptimisticEdges() const = 0; |
--- |
| 5319 |
|
--- |
5319 |
|
--- |
| 5320 |
/// Is there any call with a unknown callee. |
--- |
5320 |
/// Is there any call with a unknown callee. |
--- |
| 5321 |
virtual bool hasUnknownCallee() const = 0; |
--- |
5321 |
virtual bool hasUnknownCallee() const = 0; |
--- |
| 5322 |
|
--- |
5322 |
|
--- |
| 5323 |
/// Is there any call with a unknown callee, excluding any inline asm. |
--- |
5323 |
/// Is there any call with a unknown callee, excluding any inline asm. |
--- |
| 5324 |
virtual bool hasNonAsmUnknownCallee() const = 0; |
--- |
5324 |
virtual bool hasNonAsmUnknownCallee() const = 0; |
--- |
| 5325 |
|
--- |
5325 |
|
--- |
| 5326 |
/// Iterator for exploring the call graph. |
--- |
5326 |
/// Iterator for exploring the call graph. |
--- |
| 5327 |
AACallEdgeIterator optimisticEdgesBegin() const override { |
--- |
5327 |
AACallEdgeIterator optimisticEdgesBegin() const override { |
--- |
| 5328 |
return AACallEdgeIterator(A, getOptimisticEdges().begin()); |
--- |
5328 |
return AACallEdgeIterator(A, getOptimisticEdges().begin()); |
--- |
| 5329 |
} |
--- |
5329 |
} |
--- |
| 5330 |
|
--- |
5330 |
|
--- |
| 5331 |
/// Iterator for exploring the call graph. |
--- |
5331 |
/// Iterator for exploring the call graph. |
--- |
| 5332 |
AACallEdgeIterator optimisticEdgesEnd() const override { |
--- |
5332 |
AACallEdgeIterator optimisticEdgesEnd() const override { |
--- |
| 5333 |
return AACallEdgeIterator(A, getOptimisticEdges().end()); |
--- |
5333 |
return AACallEdgeIterator(A, getOptimisticEdges().end()); |
--- |
| 5334 |
} |
--- |
5334 |
} |
--- |
| 5335 |
|
--- |
5335 |
|
--- |
| 5336 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5336 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5337 |
static AACallEdges &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
5337 |
static AACallEdges &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 5338 |
|
--- |
5338 |
|
--- |
| 5339 |
/// See AbstractAttribute::getName() |
--- |
5339 |
/// See AbstractAttribute::getName() |
--- |
| 5340 |
const std::string getName() const override { return "AACallEdges"; } |
--- |
5340 |
const std::string getName() const override { return "AACallEdges"; } |
--- |
| 5341 |
|
--- |
5341 |
|
--- |
| 5342 |
/// See AbstractAttribute::getIdAddr() |
--- |
5342 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5343 |
const char *getIdAddr() const override { return &ID; } |
--- |
5343 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5344 |
|
--- |
5344 |
|
--- |
| 5345 |
/// This function should return true if the type of the \p AA is AACallEdges. |
--- |
5345 |
/// This function should return true if the type of the \p AA is AACallEdges. |
--- |
| 5346 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5346 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5347 |
return (AA->getIdAddr() == &ID); |
--- |
5347 |
return (AA->getIdAddr() == &ID); |
--- |
| 5348 |
} |
--- |
5348 |
} |
--- |
| 5349 |
|
--- |
5349 |
|
--- |
| 5350 |
/// Unique ID (due to the unique address) |
--- |
5350 |
/// Unique ID (due to the unique address) |
--- |
| 5351 |
static const char ID; |
--- |
5351 |
static const char ID; |
--- |
| 5352 |
}; |
--- |
5352 |
}; |
--- |
| 5353 |
|
--- |
5353 |
|
--- |
| 5354 |
// Synthetic root node for the Attributor's internal call graph. |
--- |
5354 |
// Synthetic root node for the Attributor's internal call graph. |
--- |
| 5355 |
struct AttributorCallGraph : public AACallGraphNode { |
--- |
5355 |
struct AttributorCallGraph : public AACallGraphNode { |
--- |
| 5356 |
AttributorCallGraph(Attributor &A) : AACallGraphNode(A) {} |
0 |
5356 |
AttributorCallGraph(Attributor &A) : AACallGraphNode(A) {} |
0 |
| 5357 |
virtual ~AttributorCallGraph() = default; |
0 |
5357 |
virtual ~AttributorCallGraph() = default; |
0 |
| 5358 |
|
--- |
5358 |
|
--- |
| 5359 |
AACallEdgeIterator optimisticEdgesBegin() const override { |
0 |
5359 |
AACallEdgeIterator optimisticEdgesBegin() const override { |
0 |
| 5360 |
return AACallEdgeIterator(A, A.Functions.begin()); |
0 |
5360 |
return AACallEdgeIterator(A, A.Functions.begin()); |
0 |
| 5361 |
} |
--- |
5361 |
} |
--- |
| 5362 |
|
--- |
5362 |
|
--- |
| 5363 |
AACallEdgeIterator optimisticEdgesEnd() const override { |
0 |
5363 |
AACallEdgeIterator optimisticEdgesEnd() const override { |
0 |
| 5364 |
return AACallEdgeIterator(A, A.Functions.end()); |
0 |
5364 |
return AACallEdgeIterator(A, A.Functions.end()); |
0 |
| 5365 |
} |
--- |
5365 |
} |
--- |
| 5366 |
|
--- |
5366 |
|
--- |
| 5367 |
/// Force populate the entire call graph. |
--- |
5367 |
/// Force populate the entire call graph. |
--- |
| 5368 |
void populateAll() const { |
0 |
5368 |
void populateAll() const { |
0 |
| 5369 |
for (const AACallGraphNode *AA : optimisticEdgesRange()) { |
0 |
5369 |
for (const AACallGraphNode *AA : optimisticEdgesRange()) { |
0 |
| 5370 |
// Nothing else to do here. |
--- |
5370 |
// Nothing else to do here. |
--- |
| 5371 |
(void)AA; |
--- |
5371 |
(void)AA; |
--- |
| 5372 |
} |
--- |
5372 |
} |
--- |
| 5373 |
} |
0 |
5373 |
} |
0 |
| 5374 |
|
--- |
5374 |
|
--- |
| 5375 |
void print(); |
--- |
5375 |
void print(); |
--- |
| 5376 |
}; |
--- |
5376 |
}; |
--- |
| 5377 |
|
--- |
5377 |
|
--- |
| 5378 |
template <> struct GraphTraits { |
--- |
5378 |
template <> struct GraphTraits { |
--- |
| 5379 |
using NodeRef = AACallGraphNode *; |
--- |
5379 |
using NodeRef = AACallGraphNode *; |
--- |
| 5380 |
using ChildIteratorType = AACallEdgeIterator; |
--- |
5380 |
using ChildIteratorType = AACallEdgeIterator; |
--- |
| 5381 |
|
--- |
5381 |
|
--- |
| 5382 |
static AACallEdgeIterator child_begin(AACallGraphNode *Node) { |
--- |
5382 |
static AACallEdgeIterator child_begin(AACallGraphNode *Node) { |
--- |
| 5383 |
return Node->optimisticEdgesBegin(); |
--- |
5383 |
return Node->optimisticEdgesBegin(); |
--- |
| 5384 |
} |
--- |
5384 |
} |
--- |
| 5385 |
|
--- |
5385 |
|
--- |
| 5386 |
static AACallEdgeIterator child_end(AACallGraphNode *Node) { |
--- |
5386 |
static AACallEdgeIterator child_end(AACallGraphNode *Node) { |
--- |
| 5387 |
return Node->optimisticEdgesEnd(); |
--- |
5387 |
return Node->optimisticEdgesEnd(); |
--- |
| 5388 |
} |
--- |
5388 |
} |
--- |
| 5389 |
}; |
--- |
5389 |
}; |
--- |
| 5390 |
|
--- |
5390 |
|
--- |
| 5391 |
template <> |
--- |
5391 |
template <> |
--- |
| 5392 |
struct GraphTraits |
--- |
5392 |
struct GraphTraits |
--- |
| 5393 |
: public GraphTraits { |
--- |
5393 |
: public GraphTraits { |
--- |
| 5394 |
using nodes_iterator = AACallEdgeIterator; |
--- |
5394 |
using nodes_iterator = AACallEdgeIterator; |
--- |
| 5395 |
|
--- |
5395 |
|
--- |
| 5396 |
static AACallGraphNode *getEntryNode(AttributorCallGraph *G) { |
--- |
5396 |
static AACallGraphNode *getEntryNode(AttributorCallGraph *G) { |
--- |
| 5397 |
return static_cast(G); |
--- |
5397 |
return static_cast(G); |
--- |
| 5398 |
} |
--- |
5398 |
} |
--- |
| 5399 |
|
--- |
5399 |
|
--- |
| 5400 |
static AACallEdgeIterator nodes_begin(const AttributorCallGraph *G) { |
--- |
5400 |
static AACallEdgeIterator nodes_begin(const AttributorCallGraph *G) { |
--- |
| 5401 |
return G->optimisticEdgesBegin(); |
--- |
5401 |
return G->optimisticEdgesBegin(); |
--- |
| 5402 |
} |
--- |
5402 |
} |
--- |
| 5403 |
|
--- |
5403 |
|
--- |
| 5404 |
static AACallEdgeIterator nodes_end(const AttributorCallGraph *G) { |
--- |
5404 |
static AACallEdgeIterator nodes_end(const AttributorCallGraph *G) { |
--- |
| 5405 |
return G->optimisticEdgesEnd(); |
--- |
5405 |
return G->optimisticEdgesEnd(); |
--- |
| 5406 |
} |
--- |
5406 |
} |
--- |
| 5407 |
}; |
--- |
5407 |
}; |
--- |
| 5408 |
|
--- |
5408 |
|
--- |
| 5409 |
template <> |
--- |
5409 |
template <> |
--- |
| 5410 |
struct DOTGraphTraits : public DefaultDOTGraphTraits { |
--- |
5410 |
struct DOTGraphTraits : public DefaultDOTGraphTraits { |
--- |
| 5411 |
DOTGraphTraits(bool Simple = false) : DefaultDOTGraphTraits(Simple) {} |
--- |
5411 |
DOTGraphTraits(bool Simple = false) : DefaultDOTGraphTraits(Simple) {} |
--- |
| 5412 |
|
--- |
5412 |
|
--- |
| 5413 |
std::string getNodeLabel(const AACallGraphNode *Node, |
--- |
5413 |
std::string getNodeLabel(const AACallGraphNode *Node, |
--- |
| 5414 |
const AttributorCallGraph *Graph) { |
--- |
5414 |
const AttributorCallGraph *Graph) { |
--- |
| 5415 |
const AACallEdges *AACE = static_cast(Node); |
--- |
5415 |
const AACallEdges *AACE = static_cast(Node); |
--- |
| 5416 |
return AACE->getAssociatedFunction()->getName().str(); |
--- |
5416 |
return AACE->getAssociatedFunction()->getName().str(); |
--- |
| 5417 |
} |
--- |
5417 |
} |
--- |
| 5418 |
|
--- |
5418 |
|
--- |
| 5419 |
static bool isNodeHidden(const AACallGraphNode *Node, |
--- |
5419 |
static bool isNodeHidden(const AACallGraphNode *Node, |
--- |
| 5420 |
const AttributorCallGraph *Graph) { |
--- |
5420 |
const AttributorCallGraph *Graph) { |
--- |
| 5421 |
// Hide the synth root. |
--- |
5421 |
// Hide the synth root. |
--- |
| 5422 |
return static_cast(Graph) == Node; |
--- |
5422 |
return static_cast(Graph) == Node; |
--- |
| 5423 |
} |
--- |
5423 |
} |
--- |
| 5424 |
}; |
--- |
5424 |
}; |
--- |
| 5425 |
|
--- |
5425 |
|
--- |
| 5426 |
struct AAExecutionDomain |
--- |
5426 |
struct AAExecutionDomain |
--- |
| 5427 |
: public StateWrapper { |
--- |
5427 |
: public StateWrapper { |
--- |
| 5428 |
using Base = StateWrapper; |
--- |
5428 |
using Base = StateWrapper; |
--- |
| 5429 |
AAExecutionDomain(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
5429 |
AAExecutionDomain(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 5430 |
|
--- |
5430 |
|
--- |
| 5431 |
/// Summary about the execution domain of a block or instruction. |
--- |
5431 |
/// Summary about the execution domain of a block or instruction. |
--- |
| 5432 |
struct ExecutionDomainTy { |
--- |
5432 |
struct ExecutionDomainTy { |
--- |
| 5433 |
using BarriersSetTy = SmallPtrSet; |
--- |
5433 |
using BarriersSetTy = SmallPtrSet; |
--- |
| 5434 |
using AssumesSetTy = SmallPtrSet; |
--- |
5434 |
using AssumesSetTy = SmallPtrSet; |
--- |
| 5435 |
|
--- |
5435 |
|
--- |
| 5436 |
void addAssumeInst(Attributor &A, AssumeInst &AI) { |
--- |
5436 |
void addAssumeInst(Attributor &A, AssumeInst &AI) { |
--- |
| 5437 |
EncounteredAssumes.insert(&AI); |
--- |
5437 |
EncounteredAssumes.insert(&AI); |
--- |
| 5438 |
} |
--- |
5438 |
} |
--- |
| 5439 |
|
--- |
5439 |
|
--- |
| 5440 |
void addAlignedBarrier(Attributor &A, CallBase &CB) { |
--- |
5440 |
void addAlignedBarrier(Attributor &A, CallBase &CB) { |
--- |
| 5441 |
AlignedBarriers.insert(&CB); |
--- |
5441 |
AlignedBarriers.insert(&CB); |
--- |
| 5442 |
} |
--- |
5442 |
} |
--- |
| 5443 |
|
--- |
5443 |
|
--- |
| 5444 |
void clearAssumeInstAndAlignedBarriers() { |
--- |
5444 |
void clearAssumeInstAndAlignedBarriers() { |
--- |
| 5445 |
EncounteredAssumes.clear(); |
--- |
5445 |
EncounteredAssumes.clear(); |
--- |
| 5446 |
AlignedBarriers.clear(); |
--- |
5446 |
AlignedBarriers.clear(); |
--- |
| 5447 |
} |
--- |
5447 |
} |
--- |
| 5448 |
|
--- |
5448 |
|
--- |
| 5449 |
bool IsExecutedByInitialThreadOnly = true; |
--- |
5449 |
bool IsExecutedByInitialThreadOnly = true; |
--- |
| 5450 |
bool IsReachedFromAlignedBarrierOnly = true; |
--- |
5450 |
bool IsReachedFromAlignedBarrierOnly = true; |
--- |
| 5451 |
bool IsReachingAlignedBarrierOnly = true; |
--- |
5451 |
bool IsReachingAlignedBarrierOnly = true; |
--- |
| 5452 |
bool EncounteredNonLocalSideEffect = false; |
--- |
5452 |
bool EncounteredNonLocalSideEffect = false; |
--- |
| 5453 |
BarriersSetTy AlignedBarriers; |
--- |
5453 |
BarriersSetTy AlignedBarriers; |
--- |
| 5454 |
AssumesSetTy EncounteredAssumes; |
--- |
5454 |
AssumesSetTy EncounteredAssumes; |
--- |
| 5455 |
}; |
--- |
5455 |
}; |
--- |
| 5456 |
|
--- |
5456 |
|
--- |
| 5457 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5457 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5458 |
static AAExecutionDomain &createForPosition(const IRPosition &IRP, |
--- |
5458 |
static AAExecutionDomain &createForPosition(const IRPosition &IRP, |
--- |
| 5459 |
Attributor &A); |
--- |
5459 |
Attributor &A); |
--- |
| 5460 |
|
--- |
5460 |
|
--- |
| 5461 |
/// See AbstractAttribute::getName(). |
--- |
5461 |
/// See AbstractAttribute::getName(). |
--- |
| 5462 |
const std::string getName() const override { return "AAExecutionDomain"; } |
--- |
5462 |
const std::string getName() const override { return "AAExecutionDomain"; } |
--- |
| 5463 |
|
--- |
5463 |
|
--- |
| 5464 |
/// See AbstractAttribute::getIdAddr(). |
--- |
5464 |
/// See AbstractAttribute::getIdAddr(). |
--- |
| 5465 |
const char *getIdAddr() const override { return &ID; } |
--- |
5465 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5466 |
|
--- |
5466 |
|
--- |
| 5467 |
/// Check if an instruction is executed only by the initial thread. |
--- |
5467 |
/// Check if an instruction is executed only by the initial thread. |
--- |
| 5468 |
bool isExecutedByInitialThreadOnly(const Instruction &I) const { |
--- |
5468 |
bool isExecutedByInitialThreadOnly(const Instruction &I) const { |
--- |
| 5469 |
return isExecutedByInitialThreadOnly(*I.getParent()); |
--- |
5469 |
return isExecutedByInitialThreadOnly(*I.getParent()); |
--- |
| 5470 |
} |
--- |
5470 |
} |
--- |
| 5471 |
|
--- |
5471 |
|
--- |
| 5472 |
/// Check if a basic block is executed only by the initial thread. |
--- |
5472 |
/// Check if a basic block is executed only by the initial thread. |
--- |
| 5473 |
virtual bool isExecutedByInitialThreadOnly(const BasicBlock &) const = 0; |
--- |
5473 |
virtual bool isExecutedByInitialThreadOnly(const BasicBlock &) const = 0; |
--- |
| 5474 |
|
--- |
5474 |
|
--- |
| 5475 |
/// Check if the instruction \p I is executed in an aligned region, that is, |
--- |
5475 |
/// Check if the instruction \p I is executed in an aligned region, that is, |
--- |
| 5476 |
/// the synchronizing effects before and after \p I are both aligned barriers. |
--- |
5476 |
/// the synchronizing effects before and after \p I are both aligned barriers. |
--- |
| 5477 |
/// This effectively means all threads execute \p I together. |
--- |
5477 |
/// This effectively means all threads execute \p I together. |
--- |
| 5478 |
virtual bool isExecutedInAlignedRegion(Attributor &A, |
--- |
5478 |
virtual bool isExecutedInAlignedRegion(Attributor &A, |
--- |
| 5479 |
const Instruction &I) const = 0; |
--- |
5479 |
const Instruction &I) const = 0; |
--- |
| 5480 |
|
--- |
5480 |
|
--- |
| 5481 |
virtual ExecutionDomainTy getExecutionDomain(const BasicBlock &) const = 0; |
--- |
5481 |
virtual ExecutionDomainTy getExecutionDomain(const BasicBlock &) const = 0; |
--- |
| 5482 |
/// Return the execution domain with which the call \p CB is entered and the |
--- |
5482 |
/// Return the execution domain with which the call \p CB is entered and the |
--- |
| 5483 |
/// one with which it is left. |
--- |
5483 |
/// one with which it is left. |
--- |
| 5484 |
virtual std::pair |
--- |
5484 |
virtual std::pair |
--- |
| 5485 |
getExecutionDomain(const CallBase &CB) const = 0; |
--- |
5485 |
getExecutionDomain(const CallBase &CB) const = 0; |
--- |
| 5486 |
virtual ExecutionDomainTy getFunctionExecutionDomain() const = 0; |
--- |
5486 |
virtual ExecutionDomainTy getFunctionExecutionDomain() const = 0; |
--- |
| 5487 |
|
--- |
5487 |
|
--- |
| 5488 |
/// Helper function to determine if \p FI is a no-op given the information |
--- |
5488 |
/// Helper function to determine if \p FI is a no-op given the information |
--- |
| 5489 |
/// about its execution from \p ExecDomainAA. |
--- |
5489 |
/// about its execution from \p ExecDomainAA. |
--- |
| 5490 |
virtual bool isNoOpFence(const FenceInst &FI) const = 0; |
--- |
5490 |
virtual bool isNoOpFence(const FenceInst &FI) const = 0; |
--- |
| 5491 |
|
--- |
5491 |
|
--- |
| 5492 |
/// This function should return true if the type of the \p AA is |
--- |
5492 |
/// This function should return true if the type of the \p AA is |
--- |
| 5493 |
/// AAExecutionDomain. |
--- |
5493 |
/// AAExecutionDomain. |
--- |
| 5494 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5494 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5495 |
return (AA->getIdAddr() == &ID); |
--- |
5495 |
return (AA->getIdAddr() == &ID); |
--- |
| 5496 |
} |
--- |
5496 |
} |
--- |
| 5497 |
|
--- |
5497 |
|
--- |
| 5498 |
/// Unique ID (due to the unique address) |
--- |
5498 |
/// Unique ID (due to the unique address) |
--- |
| 5499 |
static const char ID; |
--- |
5499 |
static const char ID; |
--- |
| 5500 |
}; |
--- |
5500 |
}; |
--- |
| 5501 |
|
--- |
5501 |
|
--- |
| 5502 |
/// An abstract Attribute for computing reachability between functions. |
--- |
5502 |
/// An abstract Attribute for computing reachability between functions. |
--- |
| 5503 |
struct AAInterFnReachability |
--- |
5503 |
struct AAInterFnReachability |
--- |
| 5504 |
: public StateWrapper { |
--- |
5504 |
: public StateWrapper { |
--- |
| 5505 |
using Base = StateWrapper; |
--- |
5505 |
using Base = StateWrapper; |
--- |
| 5506 |
|
--- |
5506 |
|
--- |
| 5507 |
AAInterFnReachability(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
5507 |
AAInterFnReachability(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 5508 |
|
--- |
5508 |
|
--- |
| 5509 |
/// If the function represented by this possition can reach \p Fn. |
--- |
5509 |
/// If the function represented by this possition can reach \p Fn. |
--- |
| 5510 |
bool canReach(Attributor &A, const Function &Fn) const { |
--- |
5510 |
bool canReach(Attributor &A, const Function &Fn) const { |
--- |
| 5511 |
Function *Scope = getAnchorScope(); |
--- |
5511 |
Function *Scope = getAnchorScope(); |
--- |
| 5512 |
if (!Scope || Scope->isDeclaration()) |
--- |
5512 |
if (!Scope || Scope->isDeclaration()) |
--- |
| 5513 |
return true; |
--- |
5513 |
return true; |
--- |
| 5514 |
return instructionCanReach(A, Scope->getEntryBlock().front(), Fn); |
--- |
5514 |
return instructionCanReach(A, Scope->getEntryBlock().front(), Fn); |
--- |
| 5515 |
} |
--- |
5515 |
} |
--- |
| 5516 |
|
--- |
5516 |
|
--- |
| 5517 |
/// Can \p Inst reach \p Fn. |
--- |
5517 |
/// Can \p Inst reach \p Fn. |
--- |
| 5518 |
/// See also AA::isPotentiallyReachable. |
--- |
5518 |
/// See also AA::isPotentiallyReachable. |
--- |
| 5519 |
virtual bool instructionCanReach( |
--- |
5519 |
virtual bool instructionCanReach( |
--- |
| 5520 |
Attributor &A, const Instruction &Inst, const Function &Fn, |
--- |
5520 |
Attributor &A, const Instruction &Inst, const Function &Fn, |
--- |
| 5521 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr, |
--- |
5521 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr, |
--- |
| 5522 |
SmallPtrSet *Visited = nullptr) const = 0; |
--- |
5522 |
SmallPtrSet *Visited = nullptr) const = 0; |
--- |
| 5523 |
|
--- |
5523 |
|
--- |
| 5524 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5524 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5525 |
static AAInterFnReachability &createForPosition(const IRPosition &IRP, |
--- |
5525 |
static AAInterFnReachability &createForPosition(const IRPosition &IRP, |
--- |
| 5526 |
Attributor &A); |
--- |
5526 |
Attributor &A); |
--- |
| 5527 |
|
--- |
5527 |
|
--- |
| 5528 |
/// See AbstractAttribute::getName() |
--- |
5528 |
/// See AbstractAttribute::getName() |
--- |
| 5529 |
const std::string getName() const override { return "AAInterFnReachability"; } |
--- |
5529 |
const std::string getName() const override { return "AAInterFnReachability"; } |
--- |
| 5530 |
|
--- |
5530 |
|
--- |
| 5531 |
/// See AbstractAttribute::getIdAddr() |
--- |
5531 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5532 |
const char *getIdAddr() const override { return &ID; } |
--- |
5532 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5533 |
|
--- |
5533 |
|
--- |
| 5534 |
/// This function should return true if the type of the \p AA is AACallEdges. |
--- |
5534 |
/// This function should return true if the type of the \p AA is AACallEdges. |
--- |
| 5535 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5535 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5536 |
return (AA->getIdAddr() == &ID); |
--- |
5536 |
return (AA->getIdAddr() == &ID); |
--- |
| 5537 |
} |
--- |
5537 |
} |
--- |
| 5538 |
|
--- |
5538 |
|
--- |
| 5539 |
/// Unique ID (due to the unique address) |
--- |
5539 |
/// Unique ID (due to the unique address) |
--- |
| 5540 |
static const char ID; |
--- |
5540 |
static const char ID; |
--- |
| 5541 |
}; |
--- |
5541 |
}; |
--- |
| 5542 |
|
--- |
5542 |
|
--- |
| 5543 |
/// An abstract Attribute for determining the necessity of the convergent |
--- |
5543 |
/// An abstract Attribute for determining the necessity of the convergent |
--- |
| 5544 |
/// attribute. |
--- |
5544 |
/// attribute. |
--- |
| 5545 |
struct AANonConvergent : public StateWrapper { |
--- |
5545 |
struct AANonConvergent : public StateWrapper { |
--- |
| 5546 |
using Base = StateWrapper; |
--- |
5546 |
using Base = StateWrapper; |
--- |
| 5547 |
|
--- |
5547 |
|
--- |
| 5548 |
AANonConvergent(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
5548 |
AANonConvergent(const IRPosition &IRP, Attributor &A) : Base(IRP) {} |
--- |
| 5549 |
|
--- |
5549 |
|
--- |
| 5550 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5550 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5551 |
static AANonConvergent &createForPosition(const IRPosition &IRP, |
--- |
5551 |
static AANonConvergent &createForPosition(const IRPosition &IRP, |
--- |
| 5552 |
Attributor &A); |
--- |
5552 |
Attributor &A); |
--- |
| 5553 |
|
--- |
5553 |
|
--- |
| 5554 |
/// Return true if "non-convergent" is assumed. |
--- |
5554 |
/// Return true if "non-convergent" is assumed. |
--- |
| 5555 |
bool isAssumedNotConvergent() const { return getAssumed(); } |
--- |
5555 |
bool isAssumedNotConvergent() const { return getAssumed(); } |
--- |
| 5556 |
|
--- |
5556 |
|
--- |
| 5557 |
/// Return true if "non-convergent" is known. |
--- |
5557 |
/// Return true if "non-convergent" is known. |
--- |
| 5558 |
bool isKnownNotConvergent() const { return getKnown(); } |
--- |
5558 |
bool isKnownNotConvergent() const { return getKnown(); } |
--- |
| 5559 |
|
--- |
5559 |
|
--- |
| 5560 |
/// See AbstractAttribute::getName() |
--- |
5560 |
/// See AbstractAttribute::getName() |
--- |
| 5561 |
const std::string getName() const override { return "AANonConvergent"; } |
--- |
5561 |
const std::string getName() const override { return "AANonConvergent"; } |
--- |
| 5562 |
|
--- |
5562 |
|
--- |
| 5563 |
/// See AbstractAttribute::getIdAddr() |
--- |
5563 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5564 |
const char *getIdAddr() const override { return &ID; } |
--- |
5564 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5565 |
|
--- |
5565 |
|
--- |
| 5566 |
/// This function should return true if the type of the \p AA is |
--- |
5566 |
/// This function should return true if the type of the \p AA is |
--- |
| 5567 |
/// AANonConvergent. |
--- |
5567 |
/// AANonConvergent. |
--- |
| 5568 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5568 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5569 |
return (AA->getIdAddr() == &ID); |
--- |
5569 |
return (AA->getIdAddr() == &ID); |
--- |
| 5570 |
} |
--- |
5570 |
} |
--- |
| 5571 |
|
--- |
5571 |
|
--- |
| 5572 |
/// Unique ID (due to the unique address) |
--- |
5572 |
/// Unique ID (due to the unique address) |
--- |
| 5573 |
static const char ID; |
--- |
5573 |
static const char ID; |
--- |
| 5574 |
}; |
--- |
5574 |
}; |
--- |
| 5575 |
|
--- |
5575 |
|
--- |
| 5576 |
/// An abstract interface for struct information. |
--- |
5576 |
/// An abstract interface for struct information. |
--- |
| 5577 |
struct AAPointerInfo : public AbstractAttribute { |
--- |
5577 |
struct AAPointerInfo : public AbstractAttribute { |
--- |
| 5578 |
AAPointerInfo(const IRPosition &IRP) : AbstractAttribute(IRP) {} |
--- |
5578 |
AAPointerInfo(const IRPosition &IRP) : AbstractAttribute(IRP) {} |
--- |
| 5579 |
|
--- |
5579 |
|
--- |
| 5580 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
5580 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 5581 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
5581 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 5582 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
5582 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 5583 |
return false; |
0 |
5583 |
return false; |
0 |
| 5584 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
5584 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 5585 |
} |
--- |
5585 |
} |
--- |
| 5586 |
|
--- |
5586 |
|
--- |
| 5587 |
enum AccessKind { |
--- |
5587 |
enum AccessKind { |
--- |
| 5588 |
// First two bits to distinguish may and must accesses. |
--- |
5588 |
// First two bits to distinguish may and must accesses. |
--- |
| 5589 |
AK_MUST = 1 << 0, |
--- |
5589 |
AK_MUST = 1 << 0, |
--- |
| 5590 |
AK_MAY = 1 << 1, |
--- |
5590 |
AK_MAY = 1 << 1, |
--- |
| 5591 |
|
--- |
5591 |
|
--- |
| 5592 |
// Then two bits for read and write. These are not exclusive. |
--- |
5592 |
// Then two bits for read and write. These are not exclusive. |
--- |
| 5593 |
AK_R = 1 << 2, |
--- |
5593 |
AK_R = 1 << 2, |
--- |
| 5594 |
AK_W = 1 << 3, |
--- |
5594 |
AK_W = 1 << 3, |
--- |
| 5595 |
AK_RW = AK_R | AK_W, |
--- |
5595 |
AK_RW = AK_R | AK_W, |
--- |
| 5596 |
|
--- |
5596 |
|
--- |
| 5597 |
// One special case for assumptions about memory content. These |
--- |
5597 |
// One special case for assumptions about memory content. These |
--- |
| 5598 |
// are neither reads nor writes. They are however always modeled |
--- |
5598 |
// are neither reads nor writes. They are however always modeled |
--- |
| 5599 |
// as read to avoid using them for write removal. |
--- |
5599 |
// as read to avoid using them for write removal. |
--- |
| 5600 |
AK_ASSUMPTION = (1 << 4) | AK_MUST, |
--- |
5600 |
AK_ASSUMPTION = (1 << 4) | AK_MUST, |
--- |
| 5601 |
|
--- |
5601 |
|
--- |
| 5602 |
// Helper for easy access. |
--- |
5602 |
// Helper for easy access. |
--- |
| 5603 |
AK_MAY_READ = AK_MAY | AK_R, |
--- |
5603 |
AK_MAY_READ = AK_MAY | AK_R, |
--- |
| 5604 |
AK_MAY_WRITE = AK_MAY | AK_W, |
--- |
5604 |
AK_MAY_WRITE = AK_MAY | AK_W, |
--- |
| 5605 |
AK_MAY_READ_WRITE = AK_MAY | AK_R | AK_W, |
--- |
5605 |
AK_MAY_READ_WRITE = AK_MAY | AK_R | AK_W, |
--- |
| 5606 |
AK_MUST_READ = AK_MUST | AK_R, |
--- |
5606 |
AK_MUST_READ = AK_MUST | AK_R, |
--- |
| 5607 |
AK_MUST_WRITE = AK_MUST | AK_W, |
--- |
5607 |
AK_MUST_WRITE = AK_MUST | AK_W, |
--- |
| 5608 |
AK_MUST_READ_WRITE = AK_MUST | AK_R | AK_W, |
--- |
5608 |
AK_MUST_READ_WRITE = AK_MUST | AK_R | AK_W, |
--- |
| 5609 |
}; |
--- |
5609 |
}; |
--- |
| 5610 |
|
--- |
5610 |
|
--- |
| 5611 |
/// A container for a list of ranges. |
--- |
5611 |
/// A container for a list of ranges. |
--- |
| 5612 |
struct RangeList { |
--- |
5612 |
struct RangeList { |
--- |
| 5613 |
// The set of ranges rarely contains more than one element, and is unlikely |
--- |
5613 |
// The set of ranges rarely contains more than one element, and is unlikely |
--- |
| 5614 |
// to contain more than say four elements. So we find the middle-ground with |
--- |
5614 |
// to contain more than say four elements. So we find the middle-ground with |
--- |
| 5615 |
// a sorted vector. This avoids hard-coding a rarely used number like "four" |
--- |
5615 |
// a sorted vector. This avoids hard-coding a rarely used number like "four" |
--- |
| 5616 |
// into every instance of a SmallSet. |
--- |
5616 |
// into every instance of a SmallSet. |
--- |
| 5617 |
using RangeTy = AA::RangeTy; |
--- |
5617 |
using RangeTy = AA::RangeTy; |
--- |
| 5618 |
using VecTy = SmallVector; |
--- |
5618 |
using VecTy = SmallVector; |
--- |
| 5619 |
using iterator = VecTy::iterator; |
--- |
5619 |
using iterator = VecTy::iterator; |
--- |
| 5620 |
using const_iterator = VecTy::const_iterator; |
--- |
5620 |
using const_iterator = VecTy::const_iterator; |
--- |
| 5621 |
VecTy Ranges; |
--- |
5621 |
VecTy Ranges; |
--- |
| 5622 |
|
--- |
5622 |
|
--- |
| 5623 |
RangeList(const RangeTy &R) { Ranges.push_back(R); } |
--- |
5623 |
RangeList(const RangeTy &R) { Ranges.push_back(R); } |
--- |
| 5624 |
RangeList(ArrayRef Offsets, int64_t Size) { |
--- |
5624 |
RangeList(ArrayRef Offsets, int64_t Size) { |
--- |
| 5625 |
Ranges.reserve(Offsets.size()); |
--- |
5625 |
Ranges.reserve(Offsets.size()); |
--- |
| 5626 |
for (unsigned i = 0, e = Offsets.size(); i != e; ++i) { |
--- |
5626 |
for (unsigned i = 0, e = Offsets.size(); i != e; ++i) { |
--- |
| 5627 |
assert(((i + 1 == e) || Offsets[i] < Offsets[i + 1]) && |
--- |
5627 |
assert(((i + 1 == e) || Offsets[i] < Offsets[i + 1]) && |
--- |
| 5628 |
"Expected strictly ascending offsets."); |
--- |
5628 |
"Expected strictly ascending offsets."); |
--- |
| 5629 |
Ranges.emplace_back(Offsets[i], Size); |
--- |
5629 |
Ranges.emplace_back(Offsets[i], Size); |
--- |
| 5630 |
} |
--- |
5630 |
} |
--- |
| 5631 |
} |
--- |
5631 |
} |
--- |
| 5632 |
RangeList() = default; |
--- |
5632 |
RangeList() = default; |
--- |
| 5633 |
|
--- |
5633 |
|
--- |
| 5634 |
iterator begin() { return Ranges.begin(); } |
--- |
5634 |
iterator begin() { return Ranges.begin(); } |
--- |
| 5635 |
iterator end() { return Ranges.end(); } |
--- |
5635 |
iterator end() { return Ranges.end(); } |
--- |
| 5636 |
const_iterator begin() const { return Ranges.begin(); } |
--- |
5636 |
const_iterator begin() const { return Ranges.begin(); } |
--- |
| 5637 |
const_iterator end() const { return Ranges.end(); } |
--- |
5637 |
const_iterator end() const { return Ranges.end(); } |
--- |
| 5638 |
|
--- |
5638 |
|
--- |
| 5639 |
// Helpers required for std::set_difference |
--- |
5639 |
// Helpers required for std::set_difference |
--- |
| 5640 |
using value_type = RangeTy; |
--- |
5640 |
using value_type = RangeTy; |
--- |
| 5641 |
void push_back(const RangeTy &R) { |
--- |
5641 |
void push_back(const RangeTy &R) { |
--- |
| 5642 |
assert((Ranges.empty() || RangeTy::OffsetLessThan(Ranges.back(), R)) && |
--- |
5642 |
assert((Ranges.empty() || RangeTy::OffsetLessThan(Ranges.back(), R)) && |
--- |
| 5643 |
"Ensure the last element is the greatest."); |
--- |
5643 |
"Ensure the last element is the greatest."); |
--- |
| 5644 |
Ranges.push_back(R); |
--- |
5644 |
Ranges.push_back(R); |
--- |
| 5645 |
} |
--- |
5645 |
} |
--- |
| 5646 |
|
--- |
5646 |
|
--- |
| 5647 |
/// Copy ranges from \p L that are not in \p R, into \p D. |
--- |
5647 |
/// Copy ranges from \p L that are not in \p R, into \p D. |
--- |
| 5648 |
static void set_difference(const RangeList &L, const RangeList &R, |
--- |
5648 |
static void set_difference(const RangeList &L, const RangeList &R, |
--- |
| 5649 |
RangeList &D) { |
--- |
5649 |
RangeList &D) { |
--- |
| 5650 |
std::set_difference(L.begin(), L.end(), R.begin(), R.end(), |
--- |
5650 |
std::set_difference(L.begin(), L.end(), R.begin(), R.end(), |
--- |
| 5651 |
std::back_inserter(D), RangeTy::OffsetLessThan); |
--- |
5651 |
std::back_inserter(D), RangeTy::OffsetLessThan); |
--- |
| 5652 |
} |
--- |
5652 |
} |
--- |
| 5653 |
|
--- |
5653 |
|
--- |
| 5654 |
unsigned size() const { return Ranges.size(); } |
--- |
5654 |
unsigned size() const { return Ranges.size(); } |
--- |
| 5655 |
|
--- |
5655 |
|
--- |
| 5656 |
bool operator==(const RangeList &OI) const { return Ranges == OI.Ranges; } |
--- |
5656 |
bool operator==(const RangeList &OI) const { return Ranges == OI.Ranges; } |
--- |
| 5657 |
|
--- |
5657 |
|
--- |
| 5658 |
/// Merge the ranges in \p RHS into the current ranges. |
--- |
5658 |
/// Merge the ranges in \p RHS into the current ranges. |
--- |
| 5659 |
/// - Merging a list of unknown ranges makes the current list unknown. |
--- |
5659 |
/// - Merging a list of unknown ranges makes the current list unknown. |
--- |
| 5660 |
/// - Ranges with the same offset are merged according to RangeTy::operator& |
--- |
5660 |
/// - Ranges with the same offset are merged according to RangeTy::operator& |
--- |
| 5661 |
/// \return true if the current RangeList changed. |
--- |
5661 |
/// \return true if the current RangeList changed. |
--- |
| 5662 |
bool merge(const RangeList &RHS) { |
--- |
5662 |
bool merge(const RangeList &RHS) { |
--- |
| 5663 |
if (isUnknown()) |
--- |
5663 |
if (isUnknown()) |
--- |
| 5664 |
return false; |
--- |
5664 |
return false; |
--- |
| 5665 |
if (RHS.isUnknown()) { |
--- |
5665 |
if (RHS.isUnknown()) { |
--- |
| 5666 |
setUnknown(); |
--- |
5666 |
setUnknown(); |
--- |
| 5667 |
return true; |
--- |
5667 |
return true; |
--- |
| 5668 |
} |
--- |
5668 |
} |
--- |
| 5669 |
|
--- |
5669 |
|
--- |
| 5670 |
if (Ranges.empty()) { |
--- |
5670 |
if (Ranges.empty()) { |
--- |
| 5671 |
Ranges = RHS.Ranges; |
--- |
5671 |
Ranges = RHS.Ranges; |
--- |
| 5672 |
return true; |
--- |
5672 |
return true; |
--- |
| 5673 |
} |
--- |
5673 |
} |
--- |
| 5674 |
|
--- |
5674 |
|
--- |
| 5675 |
bool Changed = false; |
--- |
5675 |
bool Changed = false; |
--- |
| 5676 |
auto LPos = Ranges.begin(); |
--- |
5676 |
auto LPos = Ranges.begin(); |
--- |
| 5677 |
for (auto &R : RHS.Ranges) { |
--- |
5677 |
for (auto &R : RHS.Ranges) { |
--- |
| 5678 |
auto Result = insert(LPos, R); |
--- |
5678 |
auto Result = insert(LPos, R); |
--- |
| 5679 |
if (isUnknown()) |
--- |
5679 |
if (isUnknown()) |
--- |
| 5680 |
return true; |
--- |
5680 |
return true; |
--- |
| 5681 |
LPos = Result.first; |
--- |
5681 |
LPos = Result.first; |
--- |
| 5682 |
Changed |= Result.second; |
--- |
5682 |
Changed |= Result.second; |
--- |
| 5683 |
} |
--- |
5683 |
} |
--- |
| 5684 |
return Changed; |
--- |
5684 |
return Changed; |
--- |
| 5685 |
} |
--- |
5685 |
} |
--- |
| 5686 |
|
--- |
5686 |
|
--- |
| 5687 |
/// Insert \p R at the given iterator \p Pos, and merge if necessary. |
--- |
5687 |
/// Insert \p R at the given iterator \p Pos, and merge if necessary. |
--- |
| 5688 |
/// |
--- |
5688 |
/// |
--- |
| 5689 |
/// This assumes that all ranges before \p Pos are OffsetLessThan \p R, and |
--- |
5689 |
/// This assumes that all ranges before \p Pos are OffsetLessThan \p R, and |
--- |
| 5690 |
/// then maintains the sorted order for the suffix list. |
--- |
5690 |
/// then maintains the sorted order for the suffix list. |
--- |
| 5691 |
/// |
--- |
5691 |
/// |
--- |
| 5692 |
/// \return The place of insertion and true iff anything changed. |
--- |
5692 |
/// \return The place of insertion and true iff anything changed. |
--- |
| 5693 |
std::pair insert(iterator Pos, const RangeTy &R) { |
--- |
5693 |
std::pair insert(iterator Pos, const RangeTy &R) { |
--- |
| 5694 |
if (isUnknown()) |
--- |
5694 |
if (isUnknown()) |
--- |
| 5695 |
return std::make_pair(Ranges.begin(), false); |
--- |
5695 |
return std::make_pair(Ranges.begin(), false); |
--- |
| 5696 |
if (R.offsetOrSizeAreUnknown()) { |
--- |
5696 |
if (R.offsetOrSizeAreUnknown()) { |
--- |
| 5697 |
return std::make_pair(setUnknown(), true); |
--- |
5697 |
return std::make_pair(setUnknown(), true); |
--- |
| 5698 |
} |
--- |
5698 |
} |
--- |
| 5699 |
|
--- |
5699 |
|
--- |
| 5700 |
// Maintain this as a sorted vector of unique entries. |
--- |
5700 |
// Maintain this as a sorted vector of unique entries. |
--- |
| 5701 |
auto LB = std::lower_bound(Pos, Ranges.end(), R, RangeTy::OffsetLessThan); |
--- |
5701 |
auto LB = std::lower_bound(Pos, Ranges.end(), R, RangeTy::OffsetLessThan); |
--- |
| 5702 |
if (LB == Ranges.end() || LB->Offset != R.Offset) |
--- |
5702 |
if (LB == Ranges.end() || LB->Offset != R.Offset) |
--- |
| 5703 |
return std::make_pair(Ranges.insert(LB, R), true); |
--- |
5703 |
return std::make_pair(Ranges.insert(LB, R), true); |
--- |
| 5704 |
bool Changed = *LB != R; |
--- |
5704 |
bool Changed = *LB != R; |
--- |
| 5705 |
*LB &= R; |
--- |
5705 |
*LB &= R; |
--- |
| 5706 |
if (LB->offsetOrSizeAreUnknown()) |
--- |
5706 |
if (LB->offsetOrSizeAreUnknown()) |
--- |
| 5707 |
return std::make_pair(setUnknown(), true); |
--- |
5707 |
return std::make_pair(setUnknown(), true); |
--- |
| 5708 |
return std::make_pair(LB, Changed); |
--- |
5708 |
return std::make_pair(LB, Changed); |
--- |
| 5709 |
} |
--- |
5709 |
} |
--- |
| 5710 |
|
--- |
5710 |
|
--- |
| 5711 |
/// Insert the given range \p R, maintaining sorted order. |
--- |
5711 |
/// Insert the given range \p R, maintaining sorted order. |
--- |
| 5712 |
/// |
--- |
5712 |
/// |
--- |
| 5713 |
/// \return The place of insertion and true iff anything changed. |
--- |
5713 |
/// \return The place of insertion and true iff anything changed. |
--- |
| 5714 |
std::pair insert(const RangeTy &R) { |
--- |
5714 |
std::pair insert(const RangeTy &R) { |
--- |
| 5715 |
return insert(Ranges.begin(), R); |
--- |
5715 |
return insert(Ranges.begin(), R); |
--- |
| 5716 |
} |
--- |
5716 |
} |
--- |
| 5717 |
|
--- |
5717 |
|
--- |
| 5718 |
/// Add the increment \p Inc to the offset of every range. |
--- |
5718 |
/// Add the increment \p Inc to the offset of every range. |
--- |
| 5719 |
void addToAllOffsets(int64_t Inc) { |
--- |
5719 |
void addToAllOffsets(int64_t Inc) { |
--- |
| 5720 |
assert(!isUnassigned() && |
--- |
5720 |
assert(!isUnassigned() && |
--- |
| 5721 |
"Cannot increment if the offset is not yet computed!"); |
--- |
5721 |
"Cannot increment if the offset is not yet computed!"); |
--- |
| 5722 |
if (isUnknown()) |
--- |
5722 |
if (isUnknown()) |
--- |
| 5723 |
return; |
--- |
5723 |
return; |
--- |
| 5724 |
for (auto &R : Ranges) { |
--- |
5724 |
for (auto &R : Ranges) { |
--- |
| 5725 |
R.Offset += Inc; |
--- |
5725 |
R.Offset += Inc; |
--- |
| 5726 |
} |
--- |
5726 |
} |
--- |
| 5727 |
} |
--- |
5727 |
} |
--- |
| 5728 |
|
--- |
5728 |
|
--- |
| 5729 |
/// Return true iff there is exactly one range and it is known. |
--- |
5729 |
/// Return true iff there is exactly one range and it is known. |
--- |
| 5730 |
bool isUnique() const { |
--- |
5730 |
bool isUnique() const { |
--- |
| 5731 |
return Ranges.size() == 1 && !Ranges.front().offsetOrSizeAreUnknown(); |
--- |
5731 |
return Ranges.size() == 1 && !Ranges.front().offsetOrSizeAreUnknown(); |
--- |
| 5732 |
} |
--- |
5732 |
} |
--- |
| 5733 |
|
--- |
5733 |
|
--- |
| 5734 |
/// Return the unique range, assuming it exists. |
--- |
5734 |
/// Return the unique range, assuming it exists. |
--- |
| 5735 |
const RangeTy &getUnique() const { |
--- |
5735 |
const RangeTy &getUnique() const { |
--- |
| 5736 |
assert(isUnique() && "No unique range to return!"); |
--- |
5736 |
assert(isUnique() && "No unique range to return!"); |
--- |
| 5737 |
return Ranges.front(); |
--- |
5737 |
return Ranges.front(); |
--- |
| 5738 |
} |
--- |
5738 |
} |
--- |
| 5739 |
|
--- |
5739 |
|
--- |
| 5740 |
/// Return true iff the list contains an unknown range. |
--- |
5740 |
/// Return true iff the list contains an unknown range. |
--- |
| 5741 |
bool isUnknown() const { |
--- |
5741 |
bool isUnknown() const { |
--- |
| 5742 |
if (isUnassigned()) |
--- |
5742 |
if (isUnassigned()) |
--- |
| 5743 |
return false; |
--- |
5743 |
return false; |
--- |
| 5744 |
if (Ranges.front().offsetOrSizeAreUnknown()) { |
--- |
5744 |
if (Ranges.front().offsetOrSizeAreUnknown()) { |
--- |
| 5745 |
assert(Ranges.size() == 1 && "Unknown is a singleton range."); |
--- |
5745 |
assert(Ranges.size() == 1 && "Unknown is a singleton range."); |
--- |
| 5746 |
return true; |
--- |
5746 |
return true; |
--- |
| 5747 |
} |
--- |
5747 |
} |
--- |
| 5748 |
return false; |
--- |
5748 |
return false; |
--- |
| 5749 |
} |
--- |
5749 |
} |
--- |
| 5750 |
|
--- |
5750 |
|
--- |
| 5751 |
/// Discard all ranges and insert a single unknown range. |
--- |
5751 |
/// Discard all ranges and insert a single unknown range. |
--- |
| 5752 |
iterator setUnknown() { |
--- |
5752 |
iterator setUnknown() { |
--- |
| 5753 |
Ranges.clear(); |
--- |
5753 |
Ranges.clear(); |
--- |
| 5754 |
Ranges.push_back(RangeTy::getUnknown()); |
--- |
5754 |
Ranges.push_back(RangeTy::getUnknown()); |
--- |
| 5755 |
return Ranges.begin(); |
--- |
5755 |
return Ranges.begin(); |
--- |
| 5756 |
} |
--- |
5756 |
} |
--- |
| 5757 |
|
--- |
5757 |
|
--- |
| 5758 |
/// Return true if no ranges have been inserted. |
--- |
5758 |
/// Return true if no ranges have been inserted. |
--- |
| 5759 |
bool isUnassigned() const { return Ranges.size() == 0; } |
--- |
5759 |
bool isUnassigned() const { return Ranges.size() == 0; } |
--- |
| 5760 |
}; |
--- |
5760 |
}; |
--- |
| 5761 |
|
--- |
5761 |
|
--- |
| 5762 |
/// An access description. |
--- |
5762 |
/// An access description. |
--- |
| 5763 |
struct Access { |
--- |
5763 |
struct Access { |
--- |
| 5764 |
Access(Instruction *I, int64_t Offset, int64_t Size, |
--- |
5764 |
Access(Instruction *I, int64_t Offset, int64_t Size, |
--- |
| 5765 |
std::optional Content, AccessKind Kind, Type *Ty) |
--- |
5765 |
std::optional Content, AccessKind Kind, Type *Ty) |
--- |
| 5766 |
: LocalI(I), RemoteI(I), Content(Content), Ranges(Offset, Size), |
--- |
5766 |
: LocalI(I), RemoteI(I), Content(Content), Ranges(Offset, Size), |
--- |
| 5767 |
Kind(Kind), Ty(Ty) { |
--- |
5767 |
Kind(Kind), Ty(Ty) { |
--- |
| 5768 |
verify(); |
--- |
5768 |
verify(); |
--- |
| 5769 |
} |
--- |
5769 |
} |
--- |
| 5770 |
Access(Instruction *LocalI, Instruction *RemoteI, const RangeList &Ranges, |
--- |
5770 |
Access(Instruction *LocalI, Instruction *RemoteI, const RangeList &Ranges, |
--- |
| 5771 |
std::optional Content, AccessKind K, Type *Ty) |
--- |
5771 |
std::optional Content, AccessKind K, Type *Ty) |
--- |
| 5772 |
: LocalI(LocalI), RemoteI(RemoteI), Content(Content), Ranges(Ranges), |
--- |
5772 |
: LocalI(LocalI), RemoteI(RemoteI), Content(Content), Ranges(Ranges), |
--- |
| 5773 |
Kind(K), Ty(Ty) { |
--- |
5773 |
Kind(K), Ty(Ty) { |
--- |
| 5774 |
if (Ranges.size() > 1) { |
--- |
5774 |
if (Ranges.size() > 1) { |
--- |
| 5775 |
Kind = AccessKind(Kind | AK_MAY); |
--- |
5775 |
Kind = AccessKind(Kind | AK_MAY); |
--- |
| 5776 |
Kind = AccessKind(Kind & ~AK_MUST); |
--- |
5776 |
Kind = AccessKind(Kind & ~AK_MUST); |
--- |
| 5777 |
} |
--- |
5777 |
} |
--- |
| 5778 |
verify(); |
--- |
5778 |
verify(); |
--- |
| 5779 |
} |
--- |
5779 |
} |
--- |
| 5780 |
Access(Instruction *LocalI, Instruction *RemoteI, int64_t Offset, |
--- |
5780 |
Access(Instruction *LocalI, Instruction *RemoteI, int64_t Offset, |
--- |
| 5781 |
int64_t Size, std::optional Content, AccessKind Kind, |
--- |
5781 |
int64_t Size, std::optional Content, AccessKind Kind, |
--- |
| 5782 |
Type *Ty) |
--- |
5782 |
Type *Ty) |
--- |
| 5783 |
: LocalI(LocalI), RemoteI(RemoteI), Content(Content), |
--- |
5783 |
: LocalI(LocalI), RemoteI(RemoteI), Content(Content), |
--- |
| 5784 |
Ranges(Offset, Size), Kind(Kind), Ty(Ty) { |
--- |
5784 |
Ranges(Offset, Size), Kind(Kind), Ty(Ty) { |
--- |
| 5785 |
verify(); |
--- |
5785 |
verify(); |
--- |
| 5786 |
} |
--- |
5786 |
} |
--- |
| 5787 |
Access(const Access &Other) = default; |
--- |
5787 |
Access(const Access &Other) = default; |
--- |
| 5788 |
|
--- |
5788 |
|
--- |
| 5789 |
Access &operator=(const Access &Other) = default; |
--- |
5789 |
Access &operator=(const Access &Other) = default; |
--- |
| 5790 |
bool operator==(const Access &R) const { |
--- |
5790 |
bool operator==(const Access &R) const { |
--- |
| 5791 |
return LocalI == R.LocalI && RemoteI == R.RemoteI && Ranges == R.Ranges && |
--- |
5791 |
return LocalI == R.LocalI && RemoteI == R.RemoteI && Ranges == R.Ranges && |
--- |
| 5792 |
Content == R.Content && Kind == R.Kind; |
--- |
5792 |
Content == R.Content && Kind == R.Kind; |
--- |
| 5793 |
} |
--- |
5793 |
} |
--- |
| 5794 |
bool operator!=(const Access &R) const { return !(*this == R); } |
--- |
5794 |
bool operator!=(const Access &R) const { return !(*this == R); } |
--- |
| 5795 |
|
--- |
5795 |
|
--- |
| 5796 |
Access &operator&=(const Access &R) { |
--- |
5796 |
Access &operator&=(const Access &R) { |
--- |
| 5797 |
assert(RemoteI == R.RemoteI && "Expected same instruction!"); |
--- |
5797 |
assert(RemoteI == R.RemoteI && "Expected same instruction!"); |
--- |
| 5798 |
assert(LocalI == R.LocalI && "Expected same instruction!"); |
--- |
5798 |
assert(LocalI == R.LocalI && "Expected same instruction!"); |
--- |
| 5799 |
|
--- |
5799 |
|
--- |
| 5800 |
// Note that every Access object corresponds to a unique Value, and only |
--- |
5800 |
// Note that every Access object corresponds to a unique Value, and only |
--- |
| 5801 |
// accesses to the same Value are merged. Hence we assume that all ranges |
--- |
5801 |
// accesses to the same Value are merged. Hence we assume that all ranges |
--- |
| 5802 |
// are the same size. If ranges can be different size, then the contents |
--- |
5802 |
// are the same size. If ranges can be different size, then the contents |
--- |
| 5803 |
// must be dropped. |
--- |
5803 |
// must be dropped. |
--- |
| 5804 |
Ranges.merge(R.Ranges); |
--- |
5804 |
Ranges.merge(R.Ranges); |
--- |
| 5805 |
Content = |
--- |
5805 |
Content = |
--- |
| 5806 |
AA::combineOptionalValuesInAAValueLatice(Content, R.Content, Ty); |
--- |
5806 |
AA::combineOptionalValuesInAAValueLatice(Content, R.Content, Ty); |
--- |
| 5807 |
|
--- |
5807 |
|
--- |
| 5808 |
// Combine the access kind, which results in a bitwise union. |
--- |
5808 |
// Combine the access kind, which results in a bitwise union. |
--- |
| 5809 |
// If there is more than one range, then this must be a MAY. |
--- |
5809 |
// If there is more than one range, then this must be a MAY. |
--- |
| 5810 |
// If we combine a may and a must access we clear the must bit. |
--- |
5810 |
// If we combine a may and a must access we clear the must bit. |
--- |
| 5811 |
Kind = AccessKind(Kind | R.Kind); |
--- |
5811 |
Kind = AccessKind(Kind | R.Kind); |
--- |
| 5812 |
if ((Kind & AK_MAY) || Ranges.size() > 1) { |
--- |
5812 |
if ((Kind & AK_MAY) || Ranges.size() > 1) { |
--- |
| 5813 |
Kind = AccessKind(Kind | AK_MAY); |
--- |
5813 |
Kind = AccessKind(Kind | AK_MAY); |
--- |
| 5814 |
Kind = AccessKind(Kind & ~AK_MUST); |
--- |
5814 |
Kind = AccessKind(Kind & ~AK_MUST); |
--- |
| 5815 |
} |
--- |
5815 |
} |
--- |
| 5816 |
verify(); |
--- |
5816 |
verify(); |
--- |
| 5817 |
return *this; |
--- |
5817 |
return *this; |
--- |
| 5818 |
} |
--- |
5818 |
} |
--- |
| 5819 |
|
--- |
5819 |
|
--- |
| 5820 |
void verify() { |
--- |
5820 |
void verify() { |
--- |
| 5821 |
assert(isMustAccess() + isMayAccess() == 1 && |
--- |
5821 |
assert(isMustAccess() + isMayAccess() == 1 && |
--- |
| 5822 |
"Expect must or may access, not both."); |
--- |
5822 |
"Expect must or may access, not both."); |
--- |
| 5823 |
assert(isAssumption() + isWrite() <= 1 && |
--- |
5823 |
assert(isAssumption() + isWrite() <= 1 && |
--- |
| 5824 |
"Expect assumption access or write access, never both."); |
--- |
5824 |
"Expect assumption access or write access, never both."); |
--- |
| 5825 |
assert((isMayAccess() || Ranges.size() == 1) && |
--- |
5825 |
assert((isMayAccess() || Ranges.size() == 1) && |
--- |
| 5826 |
"Cannot be a must access if there are multiple ranges."); |
--- |
5826 |
"Cannot be a must access if there are multiple ranges."); |
--- |
| 5827 |
} |
--- |
5827 |
} |
--- |
| 5828 |
|
--- |
5828 |
|
--- |
| 5829 |
/// Return the access kind. |
--- |
5829 |
/// Return the access kind. |
--- |
| 5830 |
AccessKind getKind() const { return Kind; } |
0 |
5830 |
AccessKind getKind() const { return Kind; } |
0 |
| 5831 |
|
--- |
5831 |
|
--- |
| 5832 |
/// Return true if this is a read access. |
--- |
5832 |
/// Return true if this is a read access. |
--- |
| 5833 |
bool isRead() const { return Kind & AK_R; } |
0 |
5833 |
bool isRead() const { return Kind & AK_R; } |
0 |
| 5834 |
|
--- |
5834 |
|
--- |
| 5835 |
/// Return true if this is a write access. |
--- |
5835 |
/// Return true if this is a write access. |
--- |
| 5836 |
bool isWrite() const { return Kind & AK_W; } |
0 |
5836 |
bool isWrite() const { return Kind & AK_W; } |
0 |
| 5837 |
|
--- |
5837 |
|
--- |
| 5838 |
/// Return true if this is a write access. |
--- |
5838 |
/// Return true if this is a write access. |
--- |
| 5839 |
bool isWriteOrAssumption() const { return isWrite() || isAssumption(); } |
0 |
5839 |
bool isWriteOrAssumption() const { return isWrite() || isAssumption(); } |
0 |
| 5840 |
|
--- |
5840 |
|
--- |
| 5841 |
/// Return true if this is an assumption access. |
--- |
5841 |
/// Return true if this is an assumption access. |
--- |
| 5842 |
bool isAssumption() const { return Kind == AK_ASSUMPTION; } |
0 |
5842 |
bool isAssumption() const { return Kind == AK_ASSUMPTION; } |
0 |
| 5843 |
|
--- |
5843 |
|
--- |
| 5844 |
bool isMustAccess() const { |
--- |
5844 |
bool isMustAccess() const { |
--- |
| 5845 |
bool MustAccess = Kind & AK_MUST; |
--- |
5845 |
bool MustAccess = Kind & AK_MUST; |
--- |
| 5846 |
assert((!MustAccess || Ranges.size() < 2) && |
--- |
5846 |
assert((!MustAccess || Ranges.size() < 2) && |
--- |
| 5847 |
"Cannot be a must access if there are multiple ranges."); |
--- |
5847 |
"Cannot be a must access if there are multiple ranges."); |
--- |
| 5848 |
return MustAccess; |
--- |
5848 |
return MustAccess; |
--- |
| 5849 |
} |
--- |
5849 |
} |
--- |
| 5850 |
|
--- |
5850 |
|
--- |
| 5851 |
bool isMayAccess() const { |
--- |
5851 |
bool isMayAccess() const { |
--- |
| 5852 |
bool MayAccess = Kind & AK_MAY; |
--- |
5852 |
bool MayAccess = Kind & AK_MAY; |
--- |
| 5853 |
assert((MayAccess || Ranges.size() < 2) && |
--- |
5853 |
assert((MayAccess || Ranges.size() < 2) && |
--- |
| 5854 |
"Cannot be a must access if there are multiple ranges."); |
--- |
5854 |
"Cannot be a must access if there are multiple ranges."); |
--- |
| 5855 |
return MayAccess; |
--- |
5855 |
return MayAccess; |
--- |
| 5856 |
} |
--- |
5856 |
} |
--- |
| 5857 |
|
--- |
5857 |
|
--- |
| 5858 |
/// Return the instruction that causes the access with respect to the local |
--- |
5858 |
/// Return the instruction that causes the access with respect to the local |
--- |
| 5859 |
/// scope of the associated attribute. |
--- |
5859 |
/// scope of the associated attribute. |
--- |
| 5860 |
Instruction *getLocalInst() const { return LocalI; } |
0 |
5860 |
Instruction *getLocalInst() const { return LocalI; } |
0 |
| 5861 |
|
--- |
5861 |
|
--- |
| 5862 |
/// Return the actual instruction that causes the access. |
--- |
5862 |
/// Return the actual instruction that causes the access. |
--- |
| 5863 |
Instruction *getRemoteInst() const { return RemoteI; } |
0 |
5863 |
Instruction *getRemoteInst() const { return RemoteI; } |
0 |
| 5864 |
|
--- |
5864 |
|
--- |
| 5865 |
/// Return true if the value written is not known yet. |
--- |
5865 |
/// Return true if the value written is not known yet. |
--- |
| 5866 |
bool isWrittenValueYetUndetermined() const { return !Content; } |
0 |
5866 |
bool isWrittenValueYetUndetermined() const { return !Content; } |
0 |
| 5867 |
|
--- |
5867 |
|
--- |
| 5868 |
/// Return true if the value written cannot be determined at all. |
--- |
5868 |
/// Return true if the value written cannot be determined at all. |
--- |
| 5869 |
bool isWrittenValueUnknown() const { |
0 |
5869 |
bool isWrittenValueUnknown() const { |
0 |
| 5870 |
return Content.has_value() && !*Content; |
0 |
5870 |
return Content.has_value() && !*Content; |
0 |
| 5871 |
} |
--- |
5871 |
} |
--- |
| 5872 |
|
--- |
5872 |
|
--- |
| 5873 |
/// Set the value written to nullptr, i.e., unknown. |
--- |
5873 |
/// Set the value written to nullptr, i.e., unknown. |
--- |
| 5874 |
void setWrittenValueUnknown() { Content = nullptr; } |
--- |
5874 |
void setWrittenValueUnknown() { Content = nullptr; } |
--- |
| 5875 |
|
--- |
5875 |
|
--- |
| 5876 |
/// Return the type associated with the access, if known. |
--- |
5876 |
/// Return the type associated with the access, if known. |
--- |
| 5877 |
Type *getType() const { return Ty; } |
--- |
5877 |
Type *getType() const { return Ty; } |
--- |
| 5878 |
|
--- |
5878 |
|
--- |
| 5879 |
/// Return the value writen, if any. |
--- |
5879 |
/// Return the value writen, if any. |
--- |
| 5880 |
Value *getWrittenValue() const { |
0 |
5880 |
Value *getWrittenValue() const { |
0 |
| 5881 |
assert(!isWrittenValueYetUndetermined() && |
0 |
5881 |
assert(!isWrittenValueYetUndetermined() && |
0 |
| 5882 |
"Value needs to be determined before accessing it."); |
--- |
5882 |
"Value needs to be determined before accessing it."); |
--- |
| 5883 |
return *Content; |
0 |
5883 |
return *Content; |
0 |
| 5884 |
} |
--- |
5884 |
} |
--- |
| 5885 |
|
--- |
5885 |
|
--- |
| 5886 |
/// Return the written value which can be `llvm::null` if it is not yet |
--- |
5886 |
/// Return the written value which can be `llvm::null` if it is not yet |
--- |
| 5887 |
/// determined. |
--- |
5887 |
/// determined. |
--- |
| 5888 |
std::optional getContent() const { return Content; } |
0 |
5888 |
std::optional getContent() const { return Content; } |
0 |
| 5889 |
|
--- |
5889 |
|
--- |
| 5890 |
bool hasUniqueRange() const { return Ranges.isUnique(); } |
--- |
5890 |
bool hasUniqueRange() const { return Ranges.isUnique(); } |
--- |
| 5891 |
const AA::RangeTy &getUniqueRange() const { return Ranges.getUnique(); } |
--- |
5891 |
const AA::RangeTy &getUniqueRange() const { return Ranges.getUnique(); } |
--- |
| 5892 |
|
--- |
5892 |
|
--- |
| 5893 |
/// Add a range accessed by this Access. |
--- |
5893 |
/// Add a range accessed by this Access. |
--- |
| 5894 |
/// |
--- |
5894 |
/// |
--- |
| 5895 |
/// If there are multiple ranges, then this is a "may access". |
--- |
5895 |
/// If there are multiple ranges, then this is a "may access". |
--- |
| 5896 |
void addRange(int64_t Offset, int64_t Size) { |
--- |
5896 |
void addRange(int64_t Offset, int64_t Size) { |
--- |
| 5897 |
Ranges.insert({Offset, Size}); |
--- |
5897 |
Ranges.insert({Offset, Size}); |
--- |
| 5898 |
if (!hasUniqueRange()) { |
--- |
5898 |
if (!hasUniqueRange()) { |
--- |
| 5899 |
Kind = AccessKind(Kind | AK_MAY); |
--- |
5899 |
Kind = AccessKind(Kind | AK_MAY); |
--- |
| 5900 |
Kind = AccessKind(Kind & ~AK_MUST); |
--- |
5900 |
Kind = AccessKind(Kind & ~AK_MUST); |
--- |
| 5901 |
} |
--- |
5901 |
} |
--- |
| 5902 |
} |
--- |
5902 |
} |
--- |
| 5903 |
|
--- |
5903 |
|
--- |
| 5904 |
const RangeList &getRanges() const { return Ranges; } |
--- |
5904 |
const RangeList &getRanges() const { return Ranges; } |
--- |
| 5905 |
|
--- |
5905 |
|
--- |
| 5906 |
using const_iterator = RangeList::const_iterator; |
--- |
5906 |
using const_iterator = RangeList::const_iterator; |
--- |
| 5907 |
const_iterator begin() const { return Ranges.begin(); } |
--- |
5907 |
const_iterator begin() const { return Ranges.begin(); } |
--- |
| 5908 |
const_iterator end() const { return Ranges.end(); } |
--- |
5908 |
const_iterator end() const { return Ranges.end(); } |
--- |
| 5909 |
|
--- |
5909 |
|
--- |
| 5910 |
private: |
--- |
5910 |
private: |
--- |
| 5911 |
/// The instruction responsible for the access with respect to the local |
--- |
5911 |
/// The instruction responsible for the access with respect to the local |
--- |
| 5912 |
/// scope of the associated attribute. |
--- |
5912 |
/// scope of the associated attribute. |
--- |
| 5913 |
Instruction *LocalI; |
--- |
5913 |
Instruction *LocalI; |
--- |
| 5914 |
|
--- |
5914 |
|
--- |
| 5915 |
/// The instruction responsible for the access. |
--- |
5915 |
/// The instruction responsible for the access. |
--- |
| 5916 |
Instruction *RemoteI; |
--- |
5916 |
Instruction *RemoteI; |
--- |
| 5917 |
|
--- |
5917 |
|
--- |
| 5918 |
/// The value written, if any. `std::nullopt` means "not known yet", |
--- |
5918 |
/// The value written, if any. `std::nullopt` means "not known yet", |
--- |
| 5919 |
/// `nullptr` cannot be determined. |
--- |
5919 |
/// `nullptr` cannot be determined. |
--- |
| 5920 |
std::optional Content; |
--- |
5920 |
std::optional Content; |
--- |
| 5921 |
|
--- |
5921 |
|
--- |
| 5922 |
/// Set of potential ranges accessed from the base pointer. |
--- |
5922 |
/// Set of potential ranges accessed from the base pointer. |
--- |
| 5923 |
RangeList Ranges; |
--- |
5923 |
RangeList Ranges; |
--- |
| 5924 |
|
--- |
5924 |
|
--- |
| 5925 |
/// The access kind, e.g., READ, as bitset (could be more than one). |
--- |
5925 |
/// The access kind, e.g., READ, as bitset (could be more than one). |
--- |
| 5926 |
AccessKind Kind; |
--- |
5926 |
AccessKind Kind; |
--- |
| 5927 |
|
--- |
5927 |
|
--- |
| 5928 |
/// The type of the content, thus the type read/written, can be null if not |
--- |
5928 |
/// The type of the content, thus the type read/written, can be null if not |
--- |
| 5929 |
/// available. |
--- |
5929 |
/// available. |
--- |
| 5930 |
Type *Ty; |
--- |
5930 |
Type *Ty; |
--- |
| 5931 |
}; |
--- |
5931 |
}; |
--- |
| 5932 |
|
--- |
5932 |
|
--- |
| 5933 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5933 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5934 |
static AAPointerInfo &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
5934 |
static AAPointerInfo &createForPosition(const IRPosition &IRP, Attributor &A); |
--- |
| 5935 |
|
--- |
5935 |
|
--- |
| 5936 |
/// See AbstractAttribute::getName() |
--- |
5936 |
/// See AbstractAttribute::getName() |
--- |
| 5937 |
const std::string getName() const override { return "AAPointerInfo"; } |
--- |
5937 |
const std::string getName() const override { return "AAPointerInfo"; } |
--- |
| 5938 |
|
--- |
5938 |
|
--- |
| 5939 |
/// See AbstractAttribute::getIdAddr() |
--- |
5939 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5940 |
const char *getIdAddr() const override { return &ID; } |
--- |
5940 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5941 |
|
--- |
5941 |
|
--- |
| 5942 |
/// Call \p CB on all accesses that might interfere with \p Range and return |
--- |
5942 |
/// Call \p CB on all accesses that might interfere with \p Range and return |
--- |
| 5943 |
/// true if all such accesses were known and the callback returned true for |
--- |
5943 |
/// true if all such accesses were known and the callback returned true for |
--- |
| 5944 |
/// all of them, false otherwise. An access interferes with an offset-size |
--- |
5944 |
/// all of them, false otherwise. An access interferes with an offset-size |
--- |
| 5945 |
/// pair if it might read or write that memory region. |
--- |
5945 |
/// pair if it might read or write that memory region. |
--- |
| 5946 |
virtual bool forallInterferingAccesses( |
--- |
5946 |
virtual bool forallInterferingAccesses( |
--- |
| 5947 |
AA::RangeTy Range, function_ref CB) const = 0; |
--- |
5947 |
AA::RangeTy Range, function_ref CB) const = 0; |
--- |
| 5948 |
|
--- |
5948 |
|
--- |
| 5949 |
/// Call \p CB on all accesses that might interfere with \p I and |
--- |
5949 |
/// Call \p CB on all accesses that might interfere with \p I and |
--- |
| 5950 |
/// return true if all such accesses were known and the callback returned true |
--- |
5950 |
/// return true if all such accesses were known and the callback returned true |
--- |
| 5951 |
/// for all of them, false otherwise. In contrast to forallInterferingAccesses |
--- |
5951 |
/// for all of them, false otherwise. In contrast to forallInterferingAccesses |
--- |
| 5952 |
/// this function will perform reasoning to exclude write accesses that cannot |
--- |
5952 |
/// this function will perform reasoning to exclude write accesses that cannot |
--- |
| 5953 |
/// affect the load even if they on the surface look as if they would. The |
--- |
5953 |
/// affect the load even if they on the surface look as if they would. The |
--- |
| 5954 |
/// flag \p HasBeenWrittenTo will be set to true if we know that \p I does not |
--- |
5954 |
/// flag \p HasBeenWrittenTo will be set to true if we know that \p I does not |
--- |
| 5955 |
/// read the intial value of the underlying memory. |
--- |
5955 |
/// read the intial value of the underlying memory. |
--- |
| 5956 |
virtual bool forallInterferingAccesses( |
--- |
5956 |
virtual bool forallInterferingAccesses( |
--- |
| 5957 |
Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, |
--- |
5957 |
Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, |
--- |
| 5958 |
bool FindInterferingWrites, bool FindInterferingReads, |
--- |
5958 |
bool FindInterferingWrites, bool FindInterferingReads, |
--- |
| 5959 |
function_ref CB, bool &HasBeenWrittenTo, |
--- |
5959 |
function_ref CB, bool &HasBeenWrittenTo, |
--- |
| 5960 |
AA::RangeTy &Range) const = 0; |
--- |
5960 |
AA::RangeTy &Range) const = 0; |
--- |
| 5961 |
|
--- |
5961 |
|
--- |
| 5962 |
/// This function should return true if the type of the \p AA is AAPointerInfo |
--- |
5962 |
/// This function should return true if the type of the \p AA is AAPointerInfo |
--- |
| 5963 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5963 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5964 |
return (AA->getIdAddr() == &ID); |
--- |
5964 |
return (AA->getIdAddr() == &ID); |
--- |
| 5965 |
} |
--- |
5965 |
} |
--- |
| 5966 |
|
--- |
5966 |
|
--- |
| 5967 |
/// Unique ID (due to the unique address) |
--- |
5967 |
/// Unique ID (due to the unique address) |
--- |
| 5968 |
static const char ID; |
--- |
5968 |
static const char ID; |
--- |
| 5969 |
}; |
--- |
5969 |
}; |
--- |
| 5970 |
|
--- |
5970 |
|
--- |
| 5971 |
/// An abstract attribute for getting assumption information. |
--- |
5971 |
/// An abstract attribute for getting assumption information. |
--- |
| 5972 |
struct AAAssumptionInfo |
--- |
5972 |
struct AAAssumptionInfo |
--- |
| 5973 |
: public StateWrapper, AbstractAttribute, |
--- |
5973 |
: public StateWrapper, AbstractAttribute, |
--- |
| 5974 |
DenseSet> { |
--- |
5974 |
DenseSet> { |
--- |
| 5975 |
using Base = |
--- |
5975 |
using Base = |
--- |
| 5976 |
StateWrapper, AbstractAttribute, DenseSet>; |
--- |
5976 |
StateWrapper, AbstractAttribute, DenseSet>; |
--- |
| 5977 |
|
--- |
5977 |
|
--- |
| 5978 |
AAAssumptionInfo(const IRPosition &IRP, Attributor &A, |
--- |
5978 |
AAAssumptionInfo(const IRPosition &IRP, Attributor &A, |
--- |
| 5979 |
const DenseSet &Known) |
--- |
5979 |
const DenseSet &Known) |
--- |
| 5980 |
: Base(IRP, Known) {} |
--- |
5980 |
: Base(IRP, Known) {} |
--- |
| 5981 |
|
--- |
5981 |
|
--- |
| 5982 |
/// Returns true if the assumption set contains the assumption \p Assumption. |
--- |
5982 |
/// Returns true if the assumption set contains the assumption \p Assumption. |
--- |
| 5983 |
virtual bool hasAssumption(const StringRef Assumption) const = 0; |
--- |
5983 |
virtual bool hasAssumption(const StringRef Assumption) const = 0; |
--- |
| 5984 |
|
--- |
5984 |
|
--- |
| 5985 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
5985 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 5986 |
static AAAssumptionInfo &createForPosition(const IRPosition &IRP, |
--- |
5986 |
static AAAssumptionInfo &createForPosition(const IRPosition &IRP, |
--- |
| 5987 |
Attributor &A); |
--- |
5987 |
Attributor &A); |
--- |
| 5988 |
|
--- |
5988 |
|
--- |
| 5989 |
/// See AbstractAttribute::getName() |
--- |
5989 |
/// See AbstractAttribute::getName() |
--- |
| 5990 |
const std::string getName() const override { return "AAAssumptionInfo"; } |
--- |
5990 |
const std::string getName() const override { return "AAAssumptionInfo"; } |
--- |
| 5991 |
|
--- |
5991 |
|
--- |
| 5992 |
/// See AbstractAttribute::getIdAddr() |
--- |
5992 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 5993 |
const char *getIdAddr() const override { return &ID; } |
--- |
5993 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 5994 |
|
--- |
5994 |
|
--- |
| 5995 |
/// This function should return true if the type of the \p AA is |
--- |
5995 |
/// This function should return true if the type of the \p AA is |
--- |
| 5996 |
/// AAAssumptionInfo |
--- |
5996 |
/// AAAssumptionInfo |
--- |
| 5997 |
static bool classof(const AbstractAttribute *AA) { |
--- |
5997 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 5998 |
return (AA->getIdAddr() == &ID); |
--- |
5998 |
return (AA->getIdAddr() == &ID); |
--- |
| 5999 |
} |
--- |
5999 |
} |
--- |
| 6000 |
|
--- |
6000 |
|
--- |
| 6001 |
/// Unique ID (due to the unique address) |
--- |
6001 |
/// Unique ID (due to the unique address) |
--- |
| 6002 |
static const char ID; |
--- |
6002 |
static const char ID; |
--- |
| 6003 |
}; |
--- |
6003 |
}; |
--- |
| 6004 |
|
--- |
6004 |
|
--- |
| 6005 |
/// An abstract attribute for getting all assumption underlying objects. |
--- |
6005 |
/// An abstract attribute for getting all assumption underlying objects. |
--- |
| 6006 |
struct AAUnderlyingObjects : AbstractAttribute { |
--- |
6006 |
struct AAUnderlyingObjects : AbstractAttribute { |
--- |
| 6007 |
AAUnderlyingObjects(const IRPosition &IRP) : AbstractAttribute(IRP) {} |
--- |
6007 |
AAUnderlyingObjects(const IRPosition &IRP) : AbstractAttribute(IRP) {} |
--- |
| 6008 |
|
--- |
6008 |
|
--- |
| 6009 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
6009 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 6010 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
6010 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 6011 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
6011 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 6012 |
return false; |
0 |
6012 |
return false; |
0 |
| 6013 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
6013 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 6014 |
} |
--- |
6014 |
} |
--- |
| 6015 |
|
--- |
6015 |
|
--- |
| 6016 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
6016 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 6017 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
6017 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
| 6018 |
|
--- |
6018 |
|
--- |
| 6019 |
/// Create an abstract attribute biew for the position \p IRP. |
--- |
6019 |
/// Create an abstract attribute biew for the position \p IRP. |
--- |
| 6020 |
static AAUnderlyingObjects &createForPosition(const IRPosition &IRP, |
--- |
6020 |
static AAUnderlyingObjects &createForPosition(const IRPosition &IRP, |
--- |
| 6021 |
Attributor &A); |
--- |
6021 |
Attributor &A); |
--- |
| 6022 |
|
--- |
6022 |
|
--- |
| 6023 |
/// See AbstractAttribute::getName() |
--- |
6023 |
/// See AbstractAttribute::getName() |
--- |
| 6024 |
const std::string getName() const override { return "AAUnderlyingObjects"; } |
--- |
6024 |
const std::string getName() const override { return "AAUnderlyingObjects"; } |
--- |
| 6025 |
|
--- |
6025 |
|
--- |
| 6026 |
/// See AbstractAttribute::getIdAddr() |
--- |
6026 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 6027 |
const char *getIdAddr() const override { return &ID; } |
--- |
6027 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 6028 |
|
--- |
6028 |
|
--- |
| 6029 |
/// This function should return true if the type of the \p AA is |
--- |
6029 |
/// This function should return true if the type of the \p AA is |
--- |
| 6030 |
/// AAUnderlyingObjects. |
--- |
6030 |
/// AAUnderlyingObjects. |
--- |
| 6031 |
static bool classof(const AbstractAttribute *AA) { |
--- |
6031 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 6032 |
return (AA->getIdAddr() == &ID); |
--- |
6032 |
return (AA->getIdAddr() == &ID); |
--- |
| 6033 |
} |
--- |
6033 |
} |
--- |
| 6034 |
|
--- |
6034 |
|
--- |
| 6035 |
/// Unique ID (due to the unique address) |
--- |
6035 |
/// Unique ID (due to the unique address) |
--- |
| 6036 |
static const char ID; |
--- |
6036 |
static const char ID; |
--- |
| 6037 |
|
--- |
6037 |
|
--- |
| 6038 |
/// Check \p Pred on all underlying objects in \p Scope collected so far. |
--- |
6038 |
/// Check \p Pred on all underlying objects in \p Scope collected so far. |
--- |
| 6039 |
/// |
--- |
6039 |
/// |
--- |
| 6040 |
/// This method will evaluate \p Pred on all underlying objects in \p Scope |
--- |
6040 |
/// This method will evaluate \p Pred on all underlying objects in \p Scope |
--- |
| 6041 |
/// collected so far and return true if \p Pred holds on all of them. |
--- |
6041 |
/// collected so far and return true if \p Pred holds on all of them. |
--- |
| 6042 |
virtual bool |
--- |
6042 |
virtual bool |
--- |
| 6043 |
forallUnderlyingObjects(function_ref Pred, |
--- |
6043 |
forallUnderlyingObjects(function_ref Pred, |
--- |
| 6044 |
AA::ValueScope Scope = AA::Interprocedural) const = 0; |
--- |
6044 |
AA::ValueScope Scope = AA::Interprocedural) const = 0; |
--- |
| 6045 |
}; |
--- |
6045 |
}; |
--- |
| 6046 |
|
--- |
6046 |
|
--- |
| 6047 |
/// An abstract interface for address space information. |
--- |
6047 |
/// An abstract interface for address space information. |
--- |
| 6048 |
struct AAAddressSpace : public StateWrapper { |
--- |
6048 |
struct AAAddressSpace : public StateWrapper { |
--- |
| 6049 |
AAAddressSpace(const IRPosition &IRP, Attributor &A) |
--- |
6049 |
AAAddressSpace(const IRPosition &IRP, Attributor &A) |
--- |
| 6050 |
: StateWrapper(IRP) {} |
--- |
6050 |
: StateWrapper(IRP) {} |
--- |
| 6051 |
|
--- |
6051 |
|
--- |
| 6052 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
6052 |
/// See AbstractAttribute::isValidIRPositionForInit |
--- |
| 6053 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
6053 |
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) { |
0 |
| 6054 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
6054 |
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy()) |
0 |
| 6055 |
return false; |
0 |
6055 |
return false; |
0 |
| 6056 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
6056 |
return AbstractAttribute::isValidIRPositionForInit(A, IRP); |
0 |
| 6057 |
} |
--- |
6057 |
} |
--- |
| 6058 |
|
--- |
6058 |
|
--- |
| 6059 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
6059 |
/// See AbstractAttribute::requiresCallersForArgOrFunction |
--- |
| 6060 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
6060 |
static bool requiresCallersForArgOrFunction() { return true; } |
0 |
| 6061 |
|
--- |
6061 |
|
--- |
| 6062 |
/// Return the address space of the associated value. \p NoAddressSpace is |
--- |
6062 |
/// Return the address space of the associated value. \p NoAddressSpace is |
--- |
| 6063 |
/// returned if the associated value is dead. This functions is not supposed |
--- |
6063 |
/// returned if the associated value is dead. This functions is not supposed |
--- |
| 6064 |
/// to be called if the AA is invalid. |
--- |
6064 |
/// to be called if the AA is invalid. |
--- |
| 6065 |
virtual int32_t getAddressSpace() const = 0; |
--- |
6065 |
virtual int32_t getAddressSpace() const = 0; |
--- |
| 6066 |
|
--- |
6066 |
|
--- |
| 6067 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
6067 |
/// Create an abstract attribute view for the position \p IRP. |
--- |
| 6068 |
static AAAddressSpace &createForPosition(const IRPosition &IRP, |
--- |
6068 |
static AAAddressSpace &createForPosition(const IRPosition &IRP, |
--- |
| 6069 |
Attributor &A); |
--- |
6069 |
Attributor &A); |
--- |
| 6070 |
|
--- |
6070 |
|
--- |
| 6071 |
/// See AbstractAttribute::getName() |
--- |
6071 |
/// See AbstractAttribute::getName() |
--- |
| 6072 |
const std::string getName() const override { return "AAAddressSpace"; } |
--- |
6072 |
const std::string getName() const override { return "AAAddressSpace"; } |
--- |
| 6073 |
|
--- |
6073 |
|
--- |
| 6074 |
/// See AbstractAttribute::getIdAddr() |
--- |
6074 |
/// See AbstractAttribute::getIdAddr() |
--- |
| 6075 |
const char *getIdAddr() const override { return &ID; } |
--- |
6075 |
const char *getIdAddr() const override { return &ID; } |
--- |
| 6076 |
|
--- |
6076 |
|
--- |
| 6077 |
/// This function should return true if the type of the \p AA is |
--- |
6077 |
/// This function should return true if the type of the \p AA is |
--- |
| 6078 |
/// AAAssumptionInfo |
--- |
6078 |
/// AAAssumptionInfo |
--- |
| 6079 |
static bool classof(const AbstractAttribute *AA) { |
--- |
6079 |
static bool classof(const AbstractAttribute *AA) { |
--- |
| 6080 |
return (AA->getIdAddr() == &ID); |
--- |
6080 |
return (AA->getIdAddr() == &ID); |
--- |
| 6081 |
} |
--- |
6081 |
} |
--- |
| 6082 |
|
--- |
6082 |
|
--- |
| 6083 |
// No address space which indicates the associated value is dead. |
--- |
6083 |
// No address space which indicates the associated value is dead. |
--- |
| 6084 |
static const int32_t NoAddressSpace = -1; |
--- |
6084 |
static const int32_t NoAddressSpace = -1; |
--- |
| 6085 |
|
--- |
6085 |
|
--- |
| 6086 |
/// Unique ID (due to the unique address) |
--- |
6086 |
/// Unique ID (due to the unique address) |
--- |
| 6087 |
static const char ID; |
--- |
6087 |
static const char ID; |
--- |
| 6088 |
}; |
--- |
6088 |
}; |
--- |
| 6089 |
|
--- |
6089 |
|
--- |
| 6090 |
raw_ostream &operator<<(raw_ostream &, const AAPointerInfo::Access &); |
--- |
6090 |
raw_ostream &operator<<(raw_ostream &, const AAPointerInfo::Access &); |
--- |
| 6091 |
|
--- |
6091 |
|
--- |
| 6092 |
/// Run options, used by the pass manager. |
--- |
6092 |
/// Run options, used by the pass manager. |
--- |
| 6093 |
enum AttributorRunOption { |
--- |
6093 |
enum AttributorRunOption { |
--- |
| 6094 |
NONE = 0, |
--- |
6094 |
NONE = 0, |
--- |
| 6095 |
MODULE = 1 << 0, |
--- |
6095 |
MODULE = 1 << 0, |
--- |
| 6096 |
CGSCC = 1 << 1, |
--- |
6096 |
CGSCC = 1 << 1, |
--- |
| 6097 |
ALL = MODULE | CGSCC |
--- |
6097 |
ALL = MODULE | CGSCC |
--- |
| 6098 |
}; |
--- |
6098 |
}; |
--- |
| 6099 |
|
--- |
6099 |
|
--- |
| 6100 |
namespace AA { |
--- |
6100 |
namespace AA { |
--- |
| 6101 |
/// Helper to avoid creating an AA for IR Attributes that might already be set. |
--- |
6101 |
/// Helper to avoid creating an AA for IR Attributes that might already be set. |
--- |
| 6102 |
template |
--- |
6102 |
template |
--- |
| 6103 |
bool hasAssumedIRAttr(Attributor &A, const AbstractAttribute *QueryingAA, |
0 |
6103 |
bool hasAssumedIRAttr(Attributor &A, const AbstractAttribute *QueryingAA, |
0 |
| 6104 |
const IRPosition &IRP, DepClassTy DepClass, bool &IsKnown, |
--- |
6104 |
const IRPosition &IRP, DepClassTy DepClass, bool &IsKnown, |
--- |
| 6105 |
bool IgnoreSubsumingPositions = false, |
--- |
6105 |
bool IgnoreSubsumingPositions = false, |
--- |
| 6106 |
const AAType **AAPtr = nullptr) { |
--- |
6106 |
const AAType **AAPtr = nullptr) { |
--- |
| 6107 |
IsKnown = false; |
0 |
6107 |
IsKnown = false; |
0 |
| 6108 |
switch (AK) { |
--- |
6108 |
switch (AK) { |
--- |
| 6109 |
#define CASE(ATTRNAME, AANAME, ...) \ |
--- |
6109 |
#define CASE(ATTRNAME, AANAME, ...) \ |
--- |
| 6110 |
case Attribute::ATTRNAME: { \ |
--- |
6110 |
case Attribute::ATTRNAME: { \ |
--- |
| 6111 |
if (AANAME::isImpliedByIR(A, IRP, AK, IgnoreSubsumingPositions)) \ |
--- |
6111 |
if (AANAME::isImpliedByIR(A, IRP, AK, IgnoreSubsumingPositions)) \ |
--- |
| 6112 |
return IsKnown = true; \ |
--- |
6112 |
return IsKnown = true; \ |
--- |
| 6113 |
if (!QueryingAA) \ |
--- |
6113 |
if (!QueryingAA) \ |
--- |
| 6114 |
return false; \ |
--- |
6114 |
return false; \ |
--- |
| 6115 |
const auto *AA = A.getAAFor(*QueryingAA, IRP, DepClass); \ |
--- |
6115 |
const auto *AA = A.getAAFor(*QueryingAA, IRP, DepClass); \ |
--- |
| 6116 |
if (AAPtr) \ |
--- |
6116 |
if (AAPtr) \ |
--- |
| 6117 |
*AAPtr = reinterpret_cast(AA); \ |
--- |
6117 |
*AAPtr = reinterpret_cast(AA); \ |
--- |
| 6118 |
if (!AA || !AA->isAssumed(__VA_ARGS__)) \ |
--- |
6118 |
if (!AA || !AA->isAssumed(__VA_ARGS__)) \ |
--- |
| 6119 |
return false; \ |
--- |
6119 |
return false; \ |
--- |
| 6120 |
IsKnown = AA->isKnown(__VA_ARGS__); \ |
--- |
6120 |
IsKnown = AA->isKnown(__VA_ARGS__); \ |
--- |
| 6121 |
return true; \ |
--- |
6121 |
return true; \ |
--- |
| 6122 |
} |
--- |
6122 |
} |
--- |
| 6123 |
CASE(NoUnwind, AANoUnwind, ); |
0 |
6123 |
CASE(NoUnwind, AANoUnwind, ); |
0 |
| 6124 |
CASE(WillReturn, AAWillReturn, ); |
0 |
6124 |
CASE(WillReturn, AAWillReturn, ); |
0 |
| 6125 |
CASE(NoFree, AANoFree, ); |
0 |
6125 |
CASE(NoFree, AANoFree, ); |
0 |
| 6126 |
CASE(NoCapture, AANoCapture, ); |
0 |
6126 |
CASE(NoCapture, AANoCapture, ); |
0 |
| 6127 |
CASE(NoRecurse, AANoRecurse, ); |
0 |
6127 |
CASE(NoRecurse, AANoRecurse, ); |
0 |
| 6128 |
CASE(NoReturn, AANoReturn, ); |
0 |
6128 |
CASE(NoReturn, AANoReturn, ); |
0 |
| 6129 |
CASE(NoSync, AANoSync, ); |
0 |
6129 |
CASE(NoSync, AANoSync, ); |
0 |
| 6130 |
CASE(NoAlias, AANoAlias, ); |
0 |
6130 |
CASE(NoAlias, AANoAlias, ); |
0 |
| 6131 |
CASE(NonNull, AANonNull, ); |
0 |
6131 |
CASE(NonNull, AANonNull, ); |
0 |
| 6132 |
CASE(MustProgress, AAMustProgress, ); |
0 |
6132 |
CASE(MustProgress, AAMustProgress, ); |
0 |
| 6133 |
CASE(NoUndef, AANoUndef, ); |
0 |
6133 |
CASE(NoUndef, AANoUndef, ); |
0 |
| 6134 |
CASE(ReadNone, AAMemoryBehavior, AAMemoryBehavior::NO_ACCESSES); |
0 |
6134 |
CASE(ReadNone, AAMemoryBehavior, AAMemoryBehavior::NO_ACCESSES); |
0 |
| 6135 |
CASE(ReadOnly, AAMemoryBehavior, AAMemoryBehavior::NO_WRITES); |
0 |
6135 |
CASE(ReadOnly, AAMemoryBehavior, AAMemoryBehavior::NO_WRITES); |
0 |
| 6136 |
CASE(WriteOnly, AAMemoryBehavior, AAMemoryBehavior::NO_READS); |
--- |
6136 |
CASE(WriteOnly, AAMemoryBehavior, AAMemoryBehavior::NO_READS); |
--- |
| 6137 |
#undef CASE |
--- |
6137 |
#undef CASE |
--- |
| 6138 |
default: |
--- |
6138 |
default: |
--- |
| 6139 |
llvm_unreachable("hasAssumedIRAttr not available for this attribute kind"); |
--- |
6139 |
llvm_unreachable("hasAssumedIRAttr not available for this attribute kind"); |
--- |
| 6140 |
}; |
--- |
6140 |
}; |
--- |
| 6141 |
} |
--- |
6141 |
} |
--- |
| 6142 |
} // namespace AA |
--- |
6142 |
} // namespace AA |
--- |
| 6143 |
|
--- |
6143 |
|
--- |
| 6144 |
} // end namespace llvm |
--- |
6144 |
} // end namespace llvm |
--- |
| 6145 |
|
--- |
6145 |
|
--- |
| 6146 |
#endif // LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H |
--- |
6146 |
#endif // LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H |
--- |
| 6147 |
|
--- |
6147 |
|
--- |